Skip to content

Commit

Permalink
simplify slices
Browse files Browse the repository at this point in the history
  • Loading branch information
calbera committed Dec 19, 2024
1 parent 7743f7c commit cee7735
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
29 changes: 9 additions & 20 deletions beacon/validator/block_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,34 +311,23 @@ func (s *Service[
return ErrNilDepositIndexStart
}

blkDeposits, err := s.sb.DepositStore().GetDepositsByIndex(
depositIndex, s.chainSpec.MaxDepositsPerBlock(),
// Grab all previous deposits from genesis up to the current index + max deposits per block.
deposits, err := s.sb.DepositStore().GetDepositsByIndex(
0, depositIndex+s.chainSpec.MaxDepositsPerBlock(),
)
if err != nil {
return err
}

// Set the deposits on the block body.
var eth1Data *ctypes.Eth1Data
body.SetEth1Data(eth1Data.New(deposits.HashTreeRoot(), 0, common.ExecutionHash{}))

// Set the just the block deposits (after current index) on the block body.
s.logger.Info(
"Building block body with local deposits",
"start_index", depositIndex, "num_deposits", len(blkDeposits),
"start_index", depositIndex, "num_deposits", uint64(len(deposits))-depositIndex,
)
body.SetDeposits(blkDeposits)

// Grab all previous deposits from genesis up to the current index
// to calculate deposit root.
deposits, err := s.sb.DepositStore().GetDepositsByIndex(0, depositIndex)
if err != nil {
return err
}
deposits = append(deposits, blkDeposits...)

var eth1Data *ctypes.Eth1Data
body.SetEth1Data(eth1Data.New(
deposits.HashTreeRoot(),
0,
common.ExecutionHash{},
))
body.SetDeposits(deposits[depositIndex:])

// Set the graffiti on the block body.
sizedGraffiti := bytes.ExtendToSize([]byte(s.cfg.Graffiti), bytes.B32Size)
Expand Down
1 change: 1 addition & 0 deletions consensus-types/types/deposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ func (ds Deposits) DefineSSZ(c *ssz.Codec) {

// HashTreeRoot returns the hash tree root of the Deposits.
func (ds Deposits) HashTreeRoot() common.Root {
// TODO: determine if using HashConcurrent optimizes performance.
return ssz.HashSequential(ds)
}
2 changes: 1 addition & 1 deletion storage/deposit/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (kv *KVStore) GetDepositsByIndex(
kv.mu.RLock()
defer kv.mu.RUnlock()
var (
deposits = ctypes.Deposits{}
deposits = make(ctypes.Deposits, 0, depRange)
endIdx = startIndex + depRange
)

Expand Down

0 comments on commit cee7735

Please sign in to comment.