@@ -86,16 +86,17 @@ func (ch *Child) handleInitiateWithdrawal(l2Sequence uint64, from string, to str
8686 return nil
8787}
8888
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 {
9392 err = ch .initializeTreeFn ()
94- })
93+ }
94+ })
95+ if err != nil {
9596 return err
9697 }
9798
98- err : = ch .mk .LoadWorkingTree (blockHeight - 1 )
99+ err = ch .mk .LoadWorkingTree (blockHeight - 1 )
99100 if err == dbtypes .ErrNotFound {
100101 // must not happened
101102 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 {
116117 // TODO: maybe not return error here and roll back
117118 return fmt .Errorf ("output does not exist at index: %d" , workingOutputIndex - 1 )
118119 }
119-
120+ ch . lastOutputTime = output . OutputProposal . L1BlockTime
120121 ch .nextOutputTime = output .OutputProposal .L1BlockTime .Add (ch .bridgeInfo .BridgeConfig .SubmissionInterval * 2 / 3 )
121122 }
122123
@@ -134,6 +135,12 @@ func (ch *Child) prepareOutput(ctx context.Context) error {
134135}
135136
136137func (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+
137144 // finalize working tree if we are fully synced or block time is over next output time
138145 if ch .finalizingBlockHeight == blockHeight ||
139146 (ch .finalizingBlockHeight == 0 &&
@@ -166,8 +173,8 @@ func (ch *Child) handleTree(blockHeight uint64, latestHeight uint64, blockId []b
166173 }
167174
168175 ch .finalizingBlockHeight = 0
169- ch .nextOutputTime = blockHeader .Time .Add (ch .bridgeInfo .BridgeConfig .SubmissionInterval * 2 / 3 )
170176 ch .lastOutputTime = blockHeader .Time
177+ ch .nextOutputTime = blockHeader .Time .Add (ch .bridgeInfo .BridgeConfig .SubmissionInterval * 2 / 3 )
171178 }
172179
173180 err = ch .mk .SaveWorkingTree (blockHeight )
0 commit comments