@@ -17,6 +17,11 @@ type channelStatuser interface {
17
17
}
18
18
19
19
type inclusiveBlockRange struct { start , end uint64 }
20
+
21
+ func (r * inclusiveBlockRange ) TerminalString () string {
22
+ return fmt .Sprintf ("[%d, %d]" , r .start , r .end )
23
+ }
24
+
20
25
type syncActions struct {
21
26
clearState * eth.BlockID
22
27
blocksToPrune int
@@ -25,9 +30,17 @@ type syncActions struct {
25
30
// NOTE this range is inclusive on both ends, which is a change to previous behaviour.
26
31
}
27
32
28
- func (s syncActions ) String () string {
33
+ func (s syncActions ) TerminalString () string {
34
+ cs := "nil"
35
+ if s .clearState != nil {
36
+ cs = s .clearState .TerminalString ()
37
+ }
38
+ btl := "nil"
39
+ if s .blocksToLoad != nil {
40
+ btl = s .blocksToLoad .TerminalString ()
41
+ }
29
42
return fmt .Sprintf (
30
- "SyncActions{blocksToPrune: %d, channelsToPrune: %d, clearState: %v, blocksToLoad: %v}" , s .blocksToPrune , s .channelsToPrune , s . clearState , s . blocksToLoad )
43
+ "SyncActions{blocksToPrune: %d, channelsToPrune: %d, clearState: %v, blocksToLoad: %v}" , s .blocksToPrune , s .channelsToPrune , cs , btl )
31
44
}
32
45
33
46
// computeSyncActions determines the actions that should be taken based on the inputs provided. The inputs are the current
@@ -36,15 +49,22 @@ func (s syncActions) String() string {
36
49
// range to load into the local state, and whether to clear the state entirely. Returns an boolean indicating if the sequencer is out of sync.
37
50
func computeSyncActions [T channelStatuser ](newSyncStatus eth.SyncStatus , prevCurrentL1 eth.L1BlockRef , blocks queue.Queue [* types.Block ], channels []T , l log.Logger ) (syncActions , bool ) {
38
51
52
+ m := l .With (
53
+ "syncStatus.headL1" , newSyncStatus .HeadL1 ,
54
+ "syncStatus.currentL1" , newSyncStatus .CurrentL1 ,
55
+ "syncStatus.localSafeL2" , newSyncStatus .LocalSafeL2 ,
56
+ "syncStatus.unsafeL2" , newSyncStatus .UnsafeL2 ,
57
+ )
58
+
39
59
// PART 1: Initial checks on the sync status
40
60
if newSyncStatus .HeadL1 == (eth.L1BlockRef {}) {
41
- l .Warn ("empty sync status" )
61
+ m .Warn ("empty sync status" )
42
62
return syncActions {}, true
43
63
}
44
64
45
65
if newSyncStatus .CurrentL1 .Number < prevCurrentL1 .Number {
46
66
// This can happen when the sequencer restarts
47
- l .Warn ("sequencer currentL1 reversed" )
67
+ m .Warn ("sequencer currentL1 reversed" , "prevCurrentL1" , prevCurrentL1 )
48
68
return syncActions {}, true
49
69
}
50
70
@@ -60,7 +80,7 @@ func computeSyncActions[T channelStatuser](newSyncStatus eth.SyncStatus, prevCur
60
80
s := syncActions {
61
81
blocksToLoad : allUnsafeBlocks ,
62
82
}
63
- l .Info ("no blocks in state" , "syncActions" , s )
83
+ m .Info ("no blocks in state" , "syncActions" , s )
64
84
return s , false
65
85
}
66
86
@@ -77,10 +97,9 @@ func computeSyncActions[T channelStatuser](newSyncStatus eth.SyncStatus, prevCur
77
97
nextSafeBlockNum := newSyncStatus .LocalSafeL2 .Number + 1
78
98
79
99
if nextSafeBlockNum < oldestBlockInStateNum {
80
- l .Warn ("next safe block is below oldest block in state" ,
100
+ m .Warn ("next safe block is below oldest block in state" ,
81
101
"syncActions" , startAfresh ,
82
- "oldestBlockInState" , oldestBlockInState ,
83
- "safeL2" , newSyncStatus .LocalSafeL2 )
102
+ "oldestBlockInStateNum" , oldestBlockInStateNum )
84
103
return startAfresh , false
85
104
}
86
105
@@ -94,19 +113,17 @@ func computeSyncActions[T channelStatuser](newSyncStatus eth.SyncStatus, prevCur
94
113
// This could happen if the batcher restarted.
95
114
// The sequencer may have derived the safe chain
96
115
// from channels sent by a previous batcher instance.
97
- l .Warn ("safe head above newest block in state, clearing channel manager state" ,
116
+ m .Warn ("safe head above newest block in state, clearing channel manager state" ,
98
117
"syncActions" , startAfresh ,
99
- "safeL2" , newSyncStatus .LocalSafeL2 ,
100
118
"newestBlockInState" , eth .ToBlockID (newestBlockInState ),
101
119
)
102
120
return startAfresh , false
103
121
}
104
122
105
123
if numBlocksToDequeue > 0 && blocks [numBlocksToDequeue - 1 ].Hash () != newSyncStatus .LocalSafeL2 .Hash {
106
- l .Warn ("safe chain reorg, clearing channel manager state" ,
124
+ m .Warn ("safe chain reorg, clearing channel manager state" ,
107
125
"syncActions" , startAfresh ,
108
- "existingBlock" , eth .ToBlockID (blocks [numBlocksToDequeue - 1 ]),
109
- "safeL2" , newSyncStatus .LocalSafeL2 )
126
+ "existingBlock" , eth .ToBlockID (blocks [numBlocksToDequeue - 1 ]))
110
127
return startAfresh , false
111
128
}
112
129
@@ -120,10 +137,9 @@ func computeSyncActions[T channelStatuser](newSyncStatus eth.SyncStatus, prevCur
120
137
// for a fully submitted channel. This indicates
121
138
// that the derivation pipeline may have stalled
122
139
// e.g. because of Holocene strict ordering rules.
123
- l .Warn ("sequencer did not make expected progress" ,
140
+ m .Warn ("sequencer did not make expected progress" ,
124
141
"syncActions" , startAfresh ,
125
- "existingBlock" , ch .LatestL2 (),
126
- "safeL2" , newSyncStatus .LocalSafeL2 )
142
+ "existingBlock" , ch .LatestL2 ())
127
143
return startAfresh , false
128
144
}
129
145
}
@@ -144,9 +160,11 @@ func computeSyncActions[T channelStatuser](newSyncStatus eth.SyncStatus, prevCur
144
160
allUnsafeBlocksAboveState = & inclusiveBlockRange {newestBlockInStateNum + 1 , newSyncStatus .UnsafeL2 .Number }
145
161
}
146
162
147
- return syncActions {
163
+ a := syncActions {
148
164
blocksToPrune : int (numBlocksToDequeue ),
149
165
channelsToPrune : numChannelsToPrune ,
150
166
blocksToLoad : allUnsafeBlocksAboveState ,
151
- }, false
167
+ }
168
+ m .Debug ("computed sync actions" , "syncActions" , a )
169
+ return a , false
152
170
}
0 commit comments