@@ -86,16 +86,17 @@ func (ch *Child) handleInitiateWithdrawal(l2Sequence uint64, from string, to str
86
86
return nil
87
87
}
88
88
89
- func (ch * Child ) prepareTree (blockHeight uint64 ) error {
90
- if ch .initializeTreeFn != nil {
91
- var err error
92
- ch .initializeTree .Do (func () {
89
+ func (ch * Child ) prepareTree (blockHeight uint64 ) (err error ) {
90
+ ch .initializeTree .Do (func () {
91
+ if ch .initializeTreeFn != nil {
93
92
err = ch .initializeTreeFn ()
94
- })
93
+ }
94
+ })
95
+ if err != nil {
95
96
return err
96
97
}
97
98
98
- err : = ch .mk .LoadWorkingTree (blockHeight - 1 )
99
+ err = ch .mk .LoadWorkingTree (blockHeight - 1 )
99
100
if err == dbtypes .ErrNotFound {
100
101
// must not happened
101
102
panic (fmt .Errorf ("working tree not found at height: %d, current: %d" , blockHeight - 1 , blockHeight ))
@@ -116,7 +117,7 @@ func (ch *Child) prepareOutput(ctx context.Context) error {
116
117
// TODO: maybe not return error here and roll back
117
118
return fmt .Errorf ("output does not exist at index: %d" , workingOutputIndex - 1 )
118
119
}
119
-
120
+ ch . lastOutputTime = output . OutputProposal . L1BlockTime
120
121
ch .nextOutputTime = output .OutputProposal .L1BlockTime .Add (ch .bridgeInfo .BridgeConfig .SubmissionInterval * 2 / 3 )
121
122
}
122
123
@@ -134,6 +135,12 @@ func (ch *Child) prepareOutput(ctx context.Context) error {
134
135
}
135
136
136
137
func (ch * Child ) handleTree (blockHeight uint64 , latestHeight uint64 , blockId []byte , blockHeader cmtproto.Header ) (kvs []types.RawKV , storageRoot []byte , err error ) {
138
+ // panic if we are syncing and passed the finalizing block height
139
+ // this must not happened
140
+ if ch .finalizingBlockHeight != 0 && ch .finalizingBlockHeight < blockHeight {
141
+ panic (fmt .Errorf ("working tree not found at height: %d, current: %d" , blockHeight - 1 , blockHeight ))
142
+ }
143
+
137
144
// finalize working tree if we are fully synced or block time is over next output time
138
145
if ch .finalizingBlockHeight == blockHeight ||
139
146
(ch .finalizingBlockHeight == 0 &&
@@ -166,8 +173,8 @@ func (ch *Child) handleTree(blockHeight uint64, latestHeight uint64, blockId []b
166
173
}
167
174
168
175
ch .finalizingBlockHeight = 0
169
- ch .nextOutputTime = blockHeader .Time .Add (ch .bridgeInfo .BridgeConfig .SubmissionInterval * 2 / 3 )
170
176
ch .lastOutputTime = blockHeader .Time
177
+ ch .nextOutputTime = blockHeader .Time .Add (ch .bridgeInfo .BridgeConfig .SubmissionInterval * 2 / 3 )
171
178
}
172
179
173
180
err = ch .mk .SaveWorkingTree (blockHeight )
0 commit comments