@@ -60,7 +60,10 @@ public DebugDataDumper(final Path directory, final boolean enabled) {
60
60
}
61
61
62
62
public void saveGossipMessageDecodingError (
63
- final String topic , final Optional <UInt64 > arrivalTimestamp , final Bytes originalMessage ) {
63
+ final String topic ,
64
+ final Optional <UInt64 > arrivalTimestamp ,
65
+ final Bytes originalMessage ,
66
+ final Throwable error ) {
64
67
if (!enabled ) {
65
68
return ;
66
69
}
@@ -70,74 +73,93 @@ public void saveGossipMessageDecodingError(
70
73
Path .of (GOSSIP_MESSAGES_DIR )
71
74
.resolve (DECODING_ERROR_SUB_DIR )
72
75
.resolve (topic .replaceAll ("/" , "_" ));
73
- final String identifiers = String . format ( "on topic %s at %s" , topic , formattedTimestamp );
74
- saveBytesToFile (
75
- "gossip message with decoding error" ,
76
- identifiers ,
77
- topicPath . resolve ( fileName ),
78
- originalMessage );
76
+ final boolean success =
77
+ saveBytesToFile (
78
+ "gossip message with decoding error" , topicPath . resolve ( fileName ), originalMessage );
79
+ if ( success ) {
80
+ LOG . warn ( "Failed to decode gossip message on topic {}" , topic , error );
81
+ }
79
82
}
80
83
81
84
public void saveGossipRejectedMessageToFile (
82
- final String topic , final Optional <UInt64 > arrivalTimestamp , final Bytes decodedMessage ) {
85
+ final String topic ,
86
+ final Optional <UInt64 > arrivalTimestamp ,
87
+ final Bytes decodedMessage ,
88
+ final Optional <String > reason ) {
83
89
if (!enabled ) {
84
90
return ;
85
91
}
86
92
final String formattedTimestamp = formatOptionalTimestamp (arrivalTimestamp );
87
93
final String fileName = String .format ("%s.ssz" , formattedTimestamp );
88
94
final Path topicPath =
89
95
Path .of (GOSSIP_MESSAGES_DIR ).resolve (REJECTED_SUB_DIR ).resolve (topic .replaceAll ("/" , "_" ));
90
- final String identifiers = String .format ("on topic %s at %s" , topic , formattedTimestamp );
91
- saveBytesToFile (
92
- "rejected gossip message" , identifiers , topicPath .resolve (fileName ), decodedMessage );
96
+ final boolean success =
97
+ saveBytesToFile ("rejected gossip message" , topicPath .resolve (fileName ), decodedMessage );
98
+ if (success ) {
99
+ LOG .warn (
100
+ "Rejecting gossip message on topic {}, reason: {}" ,
101
+ topic ,
102
+ reason .orElse ("failed validation" ));
103
+ }
93
104
}
94
105
95
106
public void saveInvalidBlockToFile (
96
- final UInt64 slot , final Bytes32 blockRoot , final Bytes blockSsz ) {
107
+ final UInt64 slot ,
108
+ final Bytes32 blockRoot ,
109
+ final Bytes blockSsz ,
110
+ final String failureReason ,
111
+ final Optional <Throwable > failureCause ) {
97
112
if (!enabled ) {
98
113
return ;
99
114
}
100
115
final String fileName = String .format ("%s_%s.ssz" , slot , blockRoot .toUnprefixedHexString ());
101
- final String identifiers = String .format ("at slot %s(%s)" , slot , blockRoot );
102
- saveBytesToFile (
103
- "invalid block" , identifiers , Path .of (INVALID_BLOCK_DIR ).resolve (fileName ), blockSsz );
116
+ final boolean success =
117
+ saveBytesToFile ("invalid block" , Path .of (INVALID_BLOCK_DIR ).resolve (fileName ), blockSsz );
118
+ if (success ) {
119
+ LOG .warn (
120
+ "Rejecting invalid block at slot {} with root {} because {}" ,
121
+ slot ,
122
+ blockRoot ,
123
+ failureReason ,
124
+ failureCause .orElse (null ));
125
+ }
104
126
}
105
127
106
128
@ VisibleForTesting
107
- protected void saveBytesToFile (
108
- final String description ,
109
- final String identifiers ,
110
- final Path relativeFilePath ,
111
- final Bytes bytes ) {
129
+ protected boolean saveBytesToFile (
130
+ final String description , final Path relativeFilePath , final Bytes bytes ) {
112
131
final Path path = directory .resolve (relativeFilePath );
113
132
try {
114
133
Files .write (path , bytes .toArray ());
115
- LOG .info ("Saved {} {}" , description , identifiers );
116
134
} catch (NoSuchFileException e ) {
117
135
if (!path .getParent ().toFile ().mkdirs ()) {
118
136
LOG .error ("Failed to save {} bytes to file." , description , e );
119
- return ;
137
+ return false ;
120
138
}
121
- saveAfterCreatingTopicDirectory (description , relativeFilePath , bytes );
139
+ return saveAfterCreatingTopicDirectory (description , relativeFilePath , bytes );
122
140
} catch (IOException e ) {
123
141
LOG .error ("Failed to save {} bytes to file." , description , e );
142
+ return false ;
124
143
}
144
+ return true ;
125
145
}
126
146
127
- private void saveAfterCreatingTopicDirectory (
147
+ private boolean saveAfterCreatingTopicDirectory (
128
148
final String description , final Path relativeFilePath , final Bytes bytes ) {
129
149
final Path path = directory .resolve (relativeFilePath );
130
150
try {
131
151
Files .write (path , bytes .toArray ());
132
- LOG .info ("Saved {} " , description );
133
152
} catch (IOException e ) {
134
153
LOG .error ("Failed to save {} bytes to file." , description , e );
135
154
if (!path .getParent ().toFile ().exists ()) {
155
+ this .enabled = false ;
136
156
LOG .error (
137
157
"{} directory does not exist. Disabling saving debug data to file." ,
138
158
relativeFilePath .getParent ());
139
159
}
160
+ return false ;
140
161
}
162
+ return true ;
141
163
}
142
164
143
165
private void createDirectory (
0 commit comments