Skip to content

Commit 28582b3

Browse files
committed
check if initializing tree is executed
1 parent 94e63f5 commit 28582b3

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

executor/child/child.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ type Child struct {
5353
nextOutputTime time.Time
5454
finalizingBlockHeight uint64
5555

56-
initializeTree *sync.Once
57-
initializeTreeFn func() error
56+
initializeTreeOnce *sync.Once
57+
initializeTreeFn func() error
5858

5959
cfg nodetypes.NodeConfig
6060
db types.DB
@@ -97,7 +97,7 @@ func NewChild(
9797
node: node,
9898
mk: mk,
9999

100-
initializeTree: &sync.Once{},
100+
initializeTreeOnce: &sync.Once{},
101101

102102
cfg: cfg,
103103
db: db,

executor/child/withdraw.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,25 @@ func (ch *Child) handleInitiateWithdrawal(l2Sequence uint64, from string, to str
8686
return nil
8787
}
8888

89-
func (ch *Child) prepareTree(blockHeight uint64) (err error) {
90-
ch.initializeTree.Do(func() {
89+
func (ch *Child) initializeTree() (executed bool) {
90+
ch.initializeTreeOnce.Do(func() {
9191
if ch.initializeTreeFn != nil {
92-
err = ch.initializeTreeFn()
92+
executed = true
93+
err := ch.initializeTreeFn()
94+
if err != nil {
95+
panic("failed to initialize working tree: " + err.Error())
96+
}
9397
}
9498
})
95-
if err != nil {
96-
return err
99+
return executed
100+
}
101+
102+
func (ch *Child) prepareTree(blockHeight uint64) error {
103+
if ch.initializeTree() {
104+
return nil
97105
}
98106

99-
err = ch.mk.LoadWorkingTree(blockHeight - 1)
107+
err := ch.mk.LoadWorkingTree(blockHeight - 1)
100108
if err == dbtypes.ErrNotFound {
101109
// must not happened
102110
panic(fmt.Errorf("working tree not found at height: %d, current: %d", blockHeight-1, blockHeight))

0 commit comments

Comments
 (0)