Skip to content

Commit

Permalink
Update chain_makers.go
Browse files Browse the repository at this point in the history
  • Loading branch information
fjl committed Feb 27, 2023
1 parent 2ea06ba commit 39d9834
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,31 +208,27 @@ func (b *BlockGen) AddUncle(h *types.Header) {

// AddWithdrawal adds a withdrawal to the generated block.
func (b *BlockGen) AddWithdrawal(w *types.Withdrawal) {
// The withdrawal will be assigned the next valid index.
var idx uint64
w.Index = b.nextWithdrawalIndex()
b.withdrawals = append(b.withdrawals, w)
}

// Set the initial index to the last withdrawal index in the block + 1, if
// it exists. otherwise, determine the proper index from parent blocks
// nextWithdrawalIndex computes the index of the next withdrawal.
func (b *BlockGen) nextWithdrawalIndex() uint64 {
if len(b.withdrawals) != 0 {
idx = b.withdrawals[len(b.withdrawals)-1].Index + 1
w.Index = idx
b.withdrawals = append(b.withdrawals, w)
return
return b.withdrawals[len(b.withdrawals)-1].Index + 1
}
for i := b.i - 1; i >= 0; i-- {
if wd := b.chain[i].Withdrawals(); len(wd) != 0 {
idx = wd[len(wd)-1].Index + 1
break
return wd[len(wd)-1].Index + 1
}
if i == 0 {
// Correctly set the index if no parent had withdrawals
// Correctly set the index if no parent had withdrawals.
if wd := b.parent.Withdrawals(); len(wd) != 0 {
idx = wd[len(wd)-1].Index + 1
return wd[len(wd)-1].Index + 1
}
}
}
w.Index = idx
b.withdrawals = append(b.withdrawals, w)
return 0
}

// PrevBlock returns a previously generated block by number. It panics if
Expand Down

0 comments on commit 39d9834

Please sign in to comment.