From d606a9bc02c8b9cec6274ccd0b451b5e3ac6a01a Mon Sep 17 00:00:00 2001 From: ocnc <97242826+ocnc@users.noreply.github.com> Date: Fri, 9 Aug 2024 11:49:50 -0400 Subject: [PATCH] feat(typing): use the unwrap (#1867) --- .../chain-spec/{bartio.go => berachain.go} | 24 +++++++------------ .../pkg/state-transition/state_processor.go | 10 ++++---- .../state_processor_payload.go | 2 +- .../state_processor_randao.go | 15 ++++++------ .../state_processor_slashing.go | 14 +++++------ .../state_processor_staking.go | 4 ++-- mod/beacon/validator/block_builder.go | 2 +- mod/consensus-types/pkg/types/fork_data.go | 2 +- mod/da/pkg/store/store.go | 2 +- mod/execution/pkg/deposit/contract.go | 2 +- mod/execution/pkg/deposit/metrics.go | 2 +- mod/execution/pkg/deposit/pruner.go | 6 ++--- mod/payload/pkg/attributes/factory.go | 2 +- mod/runtime/pkg/cosmos/baseapp/abci.go | 4 +++- .../pkg/core/state/statedb.go | 2 +- .../pkg/core/state_processor.go | 3 ++- .../pkg/core/state_processor_payload.go | 2 +- .../pkg/core/state_processor_randao.go | 8 +++---- .../pkg/core/state_processor_slashing.go | 14 +++++------ .../pkg/core/state_processor_staking.go | 2 +- mod/storage/pkg/beacondb/index/validator.go | 2 +- mod/storage/pkg/beacondb/registry.go | 10 ++++---- mod/storage/pkg/beacondb/slashing.go | 4 ++-- mod/storage/pkg/beacondb/versioning.go | 2 +- mod/storage/pkg/beacondb/withdrawals.go | 2 +- mod/storage/pkg/deposit/store.go | 2 +- 26 files changed, 72 insertions(+), 72 deletions(-) rename examples/berad/pkg/chain-spec/{bartio.go => berachain.go} (80%) diff --git a/examples/berad/pkg/chain-spec/bartio.go b/examples/berad/pkg/chain-spec/berachain.go similarity index 80% rename from examples/berad/pkg/chain-spec/bartio.go rename to examples/berad/pkg/chain-spec/berachain.go index 288e3e5036..6b0d92b4ab 100644 --- a/examples/berad/pkg/chain-spec/bartio.go +++ b/examples/berad/pkg/chain-spec/berachain.go @@ -22,21 +22,15 @@ package chainspec import "github.com/berachain/beacon-kit/mod/chain-spec/pkg/chain" -type BartioChainSpec[ - DomainTypeT ~[4]byte, - EpochT ~uint64, - ExecutionAddressT ~[20]byte, - SlotT ~uint64, - CometBFTConfigT any, -] struct { - // BGTContractAddress - BGTContractAddress ExecutionAddressT `mapstructure:"bgt-contract-address"` +type BeraChainSpec struct { // SpecData is the underlying data structure for chain-specific parameters. - chain.SpecData[ - DomainTypeT, - EpochT, - ExecutionAddressT, - SlotT, - CometBFTConfigT, + chain.Spec[ + [4]byte, + uint64, + [20]byte, + uint64, + any, ] + // BGTContractAddress + BGTContractAddress [20]byte `mapstructure:"bgt-contract-address"` } diff --git a/examples/berad/pkg/state-transition/state_processor.go b/examples/berad/pkg/state-transition/state_processor.go index c024e70a56..f3ea5cf1c6 100644 --- a/examples/berad/pkg/state-transition/state_processor.go +++ b/examples/berad/pkg/state-transition/state_processor.go @@ -23,6 +23,7 @@ package transition import ( "bytes" + chainspec "github.com/berachain/beacon-kit/examples/berad/pkg/chain-spec" "github.com/berachain/beacon-kit/mod/errors" gethprimitives "github.com/berachain/beacon-kit/mod/geth-primitives" "github.com/berachain/beacon-kit/mod/primitives/pkg/common" @@ -78,7 +79,7 @@ type StateProcessor[ }, ] struct { // cs is the chain specification for the beacon chain. - cs common.ChainSpec + cs chainspec.BeraChainSpec // signer is the BLS signer used for cryptographic operations. signer crypto.BLSSigner // executionEngine is the engine responsible for executing transactions. @@ -130,7 +131,7 @@ func NewStateProcessor[ ToExecutionAddress() (gethprimitives.ExecutionAddress, error) }, ]( - cs common.ChainSpec, + cs chainspec.BeraChainSpec, executionEngine ExecutionEngine[ ExecutionPayloadT, ExecutionPayloadHeaderT, WithdrawalsT, ], @@ -206,7 +207,8 @@ func (sp *StateProcessor[ } // Process the Epoch Boundary. - if uint64(stateSlot+1)%sp.cs.SlotsPerEpoch() == 0 { + boundary := (stateSlot.Unwrap() + 1) == 0 + if boundary { if epochValidatorUpdates, err = sp.processEpoch(st); err != nil { return nil, err @@ -460,7 +462,7 @@ func (sp *StateProcessor[ return err } - if sp.cs.SlotToEpoch(slot) == math.U64(constants.GenesisEpoch) { + if sp.cs.SlotToEpoch(slot.Unwrap()) == constants.GenesisEpoch { return nil } diff --git a/examples/berad/pkg/state-transition/state_processor_payload.go b/examples/berad/pkg/state-transition/state_processor_payload.go index 1f2d5cc1ad..e13072e6a7 100644 --- a/examples/berad/pkg/state-transition/state_processor_payload.go +++ b/examples/berad/pkg/state-transition/state_processor_payload.go @@ -131,7 +131,7 @@ func (sp *StateProcessor[ // When we are verifying a payload we expect that it was produced by // the proposer for the slot that it is for. expectedMix, err := st.GetRandaoMixAtIndex( - uint64(sp.cs.SlotToEpoch(slot)) % sp.cs.EpochsPerHistoricalVector()) + sp.cs.SlotToEpoch(slot.Unwrap()) % sp.cs.EpochsPerHistoricalVector()) if err != nil { return err } diff --git a/examples/berad/pkg/state-transition/state_processor_randao.go b/examples/berad/pkg/state-transition/state_processor_randao.go index 1f3dd4d6f5..724cc6f7ca 100644 --- a/examples/berad/pkg/state-transition/state_processor_randao.go +++ b/examples/berad/pkg/state-transition/state_processor_randao.go @@ -25,6 +25,7 @@ import ( "github.com/berachain/beacon-kit/mod/primitives/pkg/constants" "github.com/berachain/beacon-kit/mod/primitives/pkg/crypto" "github.com/berachain/beacon-kit/mod/primitives/pkg/crypto/sha256" + "github.com/berachain/beacon-kit/mod/primitives/pkg/math" "github.com/berachain/beacon-kit/mod/primitives/pkg/version" "github.com/go-faster/xor" ) @@ -55,7 +56,7 @@ func (sp *StateProcessor[ return err } - epoch := sp.cs.SlotToEpoch(slot) + epoch := sp.cs.SlotToEpoch(slot.Unwrap()) body := blk.GetBody() var fd ForkDataT @@ -67,7 +68,7 @@ func (sp *StateProcessor[ if !skipVerification { signingRoot := fd.ComputeRandaoSigningRoot( - sp.cs.DomainTypeRandao(), epoch, + sp.cs.DomainTypeRandao(), math.U64(epoch), ) reveal := body.GetRandaoReveal() if err = sp.signer.VerifySignature( @@ -80,14 +81,14 @@ func (sp *StateProcessor[ } prevMix, err := st.GetRandaoMixAtIndex( - uint64(epoch) % sp.cs.EpochsPerHistoricalVector(), + epoch % sp.cs.EpochsPerHistoricalVector(), ) if err != nil { return err } return st.UpdateRandaoMixAtIndex( - uint64(epoch)%sp.cs.EpochsPerHistoricalVector(), + epoch%sp.cs.EpochsPerHistoricalVector(), sp.buildRandaoMix(prevMix, body.GetRandaoReveal()), ) } @@ -106,15 +107,15 @@ func (sp *StateProcessor[ return err } - epoch := sp.cs.SlotToEpoch(slot) + epoch := sp.cs.SlotToEpoch(slot.Unwrap()) mix, err := st.GetRandaoMixAtIndex( - uint64(epoch) % sp.cs.EpochsPerHistoricalVector(), + epoch % sp.cs.EpochsPerHistoricalVector(), ) if err != nil { return err } return st.UpdateRandaoMixAtIndex( - uint64(epoch+1)%sp.cs.EpochsPerHistoricalVector(), + (epoch+1)%sp.cs.EpochsPerHistoricalVector(), mix, ) } diff --git a/examples/berad/pkg/state-transition/state_processor_slashing.go b/examples/berad/pkg/state-transition/state_processor_slashing.go index 0fe4819d3b..04f66d08ed 100644 --- a/examples/berad/pkg/state-transition/state_processor_slashing.go +++ b/examples/berad/pkg/state-transition/state_processor_slashing.go @@ -39,7 +39,7 @@ func (sp *StateProcessor[ return err } - index := (uint64(sp.cs.SlotToEpoch(slot)) + 1) % sp.cs.EpochsPerSlashingsVector() + index := (sp.cs.SlotToEpoch(slot.Unwrap()) + 1) % sp.cs.EpochsPerSlashingsVector() return st.UpdateSlashingAtIndex(index, 0) } @@ -92,8 +92,8 @@ func (sp *StateProcessor[ } adjustedTotalSlashingBalance := min( - uint64(totalSlashings)*sp.cs.ProportionalSlashingMultiplier(), - uint64(totalBalance), + totalSlashings.Unwrap()*sp.cs.ProportionalSlashingMultiplier(), + totalBalance.Unwrap(), ) vals, err := st.GetValidators() @@ -108,16 +108,16 @@ func (sp *StateProcessor[ } //nolint:mnd // this is in the spec - slashableEpoch := (uint64(sp.cs.SlotToEpoch(slot)) + sp.cs.EpochsPerSlashingsVector()) / 2 + slashableEpoch := (sp.cs.SlotToEpoch(slot.Unwrap()) + sp.cs.EpochsPerSlashingsVector()) / 2 // Iterate through the validators and slash if needed. for _, val := range vals { if val.IsSlashed() && - (slashableEpoch == uint64(val.GetWithdrawableEpoch())) { + (slashableEpoch == val.GetWithdrawableEpoch().Unwrap()) { if err = sp.processSlash( st, val, adjustedTotalSlashingBalance, - uint64(totalBalance), + totalBalance.Unwrap(), ); err != nil { return err } @@ -139,7 +139,7 @@ func (sp *StateProcessor[ ) error { // Calculate the penalty. increment := sp.cs.EffectiveBalanceIncrement() - balDivIncrement := uint64(val.GetEffectiveBalance()) / increment + balDivIncrement := val.GetEffectiveBalance().Unwrap() / increment penaltyNumerator := balDivIncrement * adjustedTotalSlashingBalance penalty := penaltyNumerator / totalBalance * increment diff --git a/examples/berad/pkg/state-transition/state_processor_staking.go b/examples/berad/pkg/state-transition/state_processor_staking.go index 8f1ffc3227..90c1ba0276 100644 --- a/examples/berad/pkg/state-transition/state_processor_staking.go +++ b/examples/berad/pkg/state-transition/state_processor_staking.go @@ -145,7 +145,7 @@ func (sp *StateProcessor[ ) error { var ( genesisValidatorsRoot common.Root - epoch math.Epoch + epoch uint64 err error ) @@ -167,7 +167,7 @@ func (sp *StateProcessor[ } // Get the current epoch. - epoch = sp.cs.SlotToEpoch(slot) + epoch = sp.cs.SlotToEpoch(slot.Unwrap()) // Verify that the message was signed correctly. var d ForkDataT diff --git a/mod/beacon/validator/block_builder.go b/mod/beacon/validator/block_builder.go index c7fa8c7d99..cc57349d9c 100644 --- a/mod/beacon/validator/block_builder.go +++ b/mod/beacon/validator/block_builder.go @@ -141,7 +141,7 @@ func (s *Service[ var blk BeaconBlockT // Create a new block. parentBlockRoot, err := st.GetBlockRootAtIndex( - uint64(requestedSlot-1) % s.chainSpec.SlotsPerHistoricalRoot(), + (requestedSlot.Unwrap() - 1) % s.chainSpec.SlotsPerHistoricalRoot(), ) if err != nil { diff --git a/mod/consensus-types/pkg/types/fork_data.go b/mod/consensus-types/pkg/types/fork_data.go index cfc102f499..75d34a8c91 100644 --- a/mod/consensus-types/pkg/types/fork_data.go +++ b/mod/consensus-types/pkg/types/fork_data.go @@ -113,7 +113,7 @@ func (fd *ForkData) ComputeRandaoSigningRoot( epoch math.Epoch, ) common.Root { return ComputeSigningRootUInt64( - uint64(epoch), + epoch.Unwrap(), fd.ComputeDomain(domainType), ) } diff --git a/mod/da/pkg/store/store.go b/mod/da/pkg/store/store.go index f48095a48b..cbe624b2a2 100644 --- a/mod/da/pkg/store/store.go +++ b/mod/da/pkg/store/store.go @@ -63,7 +63,7 @@ func (s *Store[BeaconBlockBodyT]) IsDataAvailable( ) bool { for _, commitment := range body.GetBlobKzgCommitments() { // Check if the block data is available in the IndexDB - blockData, err := s.IndexDB.Has(uint64(slot), commitment[:]) + blockData, err := s.IndexDB.Has(slot.Unwrap(), commitment[:]) if err != nil || !blockData { return false } diff --git a/mod/execution/pkg/deposit/contract.go b/mod/execution/pkg/deposit/contract.go index a83ad3f9a0..f6e8e012da 100644 --- a/mod/execution/pkg/deposit/contract.go +++ b/mod/execution/pkg/deposit/contract.go @@ -81,7 +81,7 @@ func (dc *WrappedBeaconDepositContract[ logs, err := dc.FilterDeposit( &bind.FilterOpts{ Context: ctx, - Start: uint64(blkNum), + Start: blkNum.Unwrap(), End: (*uint64)(&blkNum), }, ) diff --git a/mod/execution/pkg/deposit/metrics.go b/mod/execution/pkg/deposit/metrics.go index 02eee75e44..7af10e3763 100644 --- a/mod/execution/pkg/deposit/metrics.go +++ b/mod/execution/pkg/deposit/metrics.go @@ -44,6 +44,6 @@ func (m *metrics) markFailedToGetBlockLogs(blockNum math.U64) { m.sink.IncrementCounter( "beacon_kit.execution.deposit.failed_to_get_block_logs", "block_num", - strconv.FormatUint(uint64(blockNum), 10), + strconv.FormatUint(blockNum.Unwrap(), 10), ) } diff --git a/mod/execution/pkg/deposit/pruner.go b/mod/execution/pkg/deposit/pruner.go index 74ca823a05..da88a9873a 100644 --- a/mod/execution/pkg/deposit/pruner.go +++ b/mod/execution/pkg/deposit/pruner.go @@ -42,11 +42,11 @@ func BuildPruneRangeFn[ } index := deposits[len(deposits)-1].GetIndex() - end := min(index, math.U64(cs.MaxDepositsPerBlock())) + end := min(index.Unwrap(), cs.MaxDepositsPerBlock()) if index < math.U64(cs.MaxDepositsPerBlock()) { - return 0, end.Unwrap() + return 0, end } - return uint64(index - math.U64(cs.MaxDepositsPerBlock())), end.Unwrap() + return index.Unwrap() - cs.MaxDepositsPerBlock(), end } } diff --git a/mod/payload/pkg/attributes/factory.go b/mod/payload/pkg/attributes/factory.go index 26ce180c62..c9819212fb 100644 --- a/mod/payload/pkg/attributes/factory.go +++ b/mod/payload/pkg/attributes/factory.go @@ -88,7 +88,7 @@ func (f *Factory[ // Get the previous randao mix. if prevRandao, err = st.GetRandaoMixAtIndex( - uint64(epoch) % f.chainSpec.EpochsPerHistoricalVector(), + epoch.Unwrap() % f.chainSpec.EpochsPerHistoricalVector(), ); err != nil { return attributes, err } diff --git a/mod/runtime/pkg/cosmos/baseapp/abci.go b/mod/runtime/pkg/cosmos/baseapp/abci.go index fdd30184f3..d723a85c92 100644 --- a/mod/runtime/pkg/cosmos/baseapp/abci.go +++ b/mod/runtime/pkg/cosmos/baseapp/abci.go @@ -136,7 +136,9 @@ func (app *BaseApp) InitChain( } if res == nil { - return nil, errors.New("application init chain handler returned a nil response") + return nil, errors.New( + "application init chain handler returned a nil response", + ) } if len(req.Validators) > 0 { diff --git a/mod/state-transition/pkg/core/state/statedb.go b/mod/state-transition/pkg/core/state/statedb.go index 1135f15039..115816152c 100644 --- a/mod/state-transition/pkg/core/state/statedb.go +++ b/mod/state-transition/pkg/core/state/statedb.go @@ -202,7 +202,7 @@ func (s *StateDB[ return nil, err } - epoch := math.Epoch(uint64(slot) / s.cs.SlotsPerEpoch()) + epoch := math.Epoch(slot.Unwrap() / s.cs.SlotsPerEpoch()) withdrawalIndex, err := s.GetNextWithdrawalIndex() if err != nil { diff --git a/mod/state-transition/pkg/core/state_processor.go b/mod/state-transition/pkg/core/state_processor.go index 4f9452e769..b864ad2ed9 100644 --- a/mod/state-transition/pkg/core/state_processor.go +++ b/mod/state-transition/pkg/core/state_processor.go @@ -205,7 +205,8 @@ func (sp *StateProcessor[ } // Process the Epoch Boundary. - if uint64(stateSlot+1)%sp.cs.SlotsPerEpoch() == 0 { + boundary := (stateSlot.Unwrap()+1)%sp.cs.SlotsPerEpoch() == 0 + if boundary { if epochValidatorUpdates, err = sp.processEpoch(st); err != nil { return nil, err diff --git a/mod/state-transition/pkg/core/state_processor_payload.go b/mod/state-transition/pkg/core/state_processor_payload.go index 64d8c4273e..3b3708597a 100644 --- a/mod/state-transition/pkg/core/state_processor_payload.go +++ b/mod/state-transition/pkg/core/state_processor_payload.go @@ -131,7 +131,7 @@ func (sp *StateProcessor[ // When we are verifying a payload we expect that it was produced by // the proposer for the slot that it is for. expectedMix, err := st.GetRandaoMixAtIndex( - uint64(sp.cs.SlotToEpoch(slot)) % sp.cs.EpochsPerHistoricalVector()) + sp.cs.SlotToEpoch(slot).Unwrap() % sp.cs.EpochsPerHistoricalVector()) if err != nil { return err } diff --git a/mod/state-transition/pkg/core/state_processor_randao.go b/mod/state-transition/pkg/core/state_processor_randao.go index bbc67ee330..ff7bf3ba9e 100644 --- a/mod/state-transition/pkg/core/state_processor_randao.go +++ b/mod/state-transition/pkg/core/state_processor_randao.go @@ -80,14 +80,14 @@ func (sp *StateProcessor[ } prevMix, err := st.GetRandaoMixAtIndex( - uint64(epoch) % sp.cs.EpochsPerHistoricalVector(), + epoch.Unwrap() % sp.cs.EpochsPerHistoricalVector(), ) if err != nil { return err } return st.UpdateRandaoMixAtIndex( - uint64(epoch)%sp.cs.EpochsPerHistoricalVector(), + epoch.Unwrap()%sp.cs.EpochsPerHistoricalVector(), sp.buildRandaoMix(prevMix, body.GetRandaoReveal()), ) } @@ -108,13 +108,13 @@ func (sp *StateProcessor[ epoch := sp.cs.SlotToEpoch(slot) mix, err := st.GetRandaoMixAtIndex( - uint64(epoch) % sp.cs.EpochsPerHistoricalVector(), + epoch.Unwrap() % sp.cs.EpochsPerHistoricalVector(), ) if err != nil { return err } return st.UpdateRandaoMixAtIndex( - uint64(epoch+1)%sp.cs.EpochsPerHistoricalVector(), + (epoch.Unwrap()+1)%sp.cs.EpochsPerHistoricalVector(), mix, ) } diff --git a/mod/state-transition/pkg/core/state_processor_slashing.go b/mod/state-transition/pkg/core/state_processor_slashing.go index 8a125c3aaf..57d091c190 100644 --- a/mod/state-transition/pkg/core/state_processor_slashing.go +++ b/mod/state-transition/pkg/core/state_processor_slashing.go @@ -39,7 +39,7 @@ func (sp *StateProcessor[ return err } - index := (uint64(sp.cs.SlotToEpoch(slot)) + 1) % sp.cs.EpochsPerSlashingsVector() + index := (sp.cs.SlotToEpoch(slot).Unwrap() + 1) % sp.cs.EpochsPerSlashingsVector() return st.UpdateSlashingAtIndex(index, 0) } @@ -92,8 +92,8 @@ func (sp *StateProcessor[ } adjustedTotalSlashingBalance := min( - uint64(totalSlashings)*sp.cs.ProportionalSlashingMultiplier(), - uint64(totalBalance), + totalSlashings.Unwrap()*sp.cs.ProportionalSlashingMultiplier(), + totalBalance.Unwrap(), ) vals, err := st.GetValidators() @@ -108,16 +108,16 @@ func (sp *StateProcessor[ } //nolint:mnd // this is in the spec - slashableEpoch := (uint64(sp.cs.SlotToEpoch(slot)) + sp.cs.EpochsPerSlashingsVector()) / 2 + slashableEpoch := (sp.cs.SlotToEpoch(slot).Unwrap() + sp.cs.EpochsPerSlashingsVector()) / 2 // Iterate through the validators and slash if needed. for _, val := range vals { if val.IsSlashed() && - (slashableEpoch == uint64(val.GetWithdrawableEpoch())) { + (slashableEpoch == val.GetWithdrawableEpoch().Unwrap()) { if err = sp.processSlash( st, val, adjustedTotalSlashingBalance, - uint64(totalBalance), + totalBalance.Unwrap(), ); err != nil { return err } @@ -139,7 +139,7 @@ func (sp *StateProcessor[ ) error { // Calculate the penalty. increment := sp.cs.EffectiveBalanceIncrement() - balDivIncrement := uint64(val.GetEffectiveBalance()) / increment + balDivIncrement := val.GetEffectiveBalance().Unwrap() / increment penaltyNumerator := balDivIncrement * adjustedTotalSlashingBalance penalty := penaltyNumerator / totalBalance * increment diff --git a/mod/state-transition/pkg/core/state_processor_staking.go b/mod/state-transition/pkg/core/state_processor_staking.go index 120203a7ed..8a995621fb 100644 --- a/mod/state-transition/pkg/core/state_processor_staking.go +++ b/mod/state-transition/pkg/core/state_processor_staking.go @@ -49,7 +49,7 @@ func (sp *StateProcessor[ } depositCount := min( sp.cs.MaxDepositsPerBlock(), - uint64(eth1Data.GetDepositCount())-index, + eth1Data.GetDepositCount().Unwrap()-index, ) _ = depositCount // TODO: Update eth1data count and check this. diff --git a/mod/storage/pkg/beacondb/index/validator.go b/mod/storage/pkg/beacondb/index/validator.go index 2faa784f07..7b845b63e1 100644 --- a/mod/storage/pkg/beacondb/index/validator.go +++ b/mod/storage/pkg/beacondb/index/validator.go @@ -97,7 +97,7 @@ func NewValidatorsIndex[ValidatorT Validator]( sdkcollections.Uint64Key, sdkcollections.Uint64Key, func(_ uint64, validator ValidatorT) (uint64, error) { - return uint64(validator.GetEffectiveBalance()), nil + return validator.GetEffectiveBalance().Unwrap(), nil }, ), CometBFTAddress: indexes.NewUnique( diff --git a/mod/storage/pkg/beacondb/registry.go b/mod/storage/pkg/beacondb/registry.go index bd04a66a2d..25c0d11655 100644 --- a/mod/storage/pkg/beacondb/registry.go +++ b/mod/storage/pkg/beacondb/registry.go @@ -62,7 +62,7 @@ func (kv *KVStore[ } // Push onto the balances list. - return kv.balances.Set(kv.ctx, idx, uint64(val.GetEffectiveBalance())) + return kv.balances.Set(kv.ctx, idx, val.GetEffectiveBalance().Unwrap()) } // UpdateValidatorAtIndex updates a validator at a specific index. @@ -73,7 +73,7 @@ func (kv *KVStore[ index math.ValidatorIndex, val ValidatorT, ) error { - return kv.validators.Set(kv.ctx, uint64(index), val) + return kv.validators.Set(kv.ctx, index.Unwrap(), val) } // ValidatorIndexByPubkey returns the validator address by index. @@ -117,7 +117,7 @@ func (kv *KVStore[ ]) ValidatorByIndex( index math.ValidatorIndex, ) (ValidatorT, error) { - val, err := kv.validators.Get(kv.ctx, uint64(index)) + val, err := kv.validators.Get(kv.ctx, index.Unwrap()) if err != nil { var t ValidatorT return t, err @@ -216,7 +216,7 @@ func (kv *KVStore[ ]) GetBalance( idx math.ValidatorIndex, ) (math.Gwei, error) { - balance, err := kv.balances.Get(kv.ctx, uint64(idx)) + balance, err := kv.balances.Get(kv.ctx, idx.Unwrap()) return math.Gwei(balance), err } @@ -228,7 +228,7 @@ func (kv *KVStore[ idx math.ValidatorIndex, balance math.Gwei, ) error { - return kv.balances.Set(kv.ctx, uint64(idx), uint64(balance)) + return kv.balances.Set(kv.ctx, idx.Unwrap(), balance.Unwrap()) } // GetBalances returns the balancse of all validator. diff --git a/mod/storage/pkg/beacondb/slashing.go b/mod/storage/pkg/beacondb/slashing.go index 94942bc8c5..97b3a9f0bc 100644 --- a/mod/storage/pkg/beacondb/slashing.go +++ b/mod/storage/pkg/beacondb/slashing.go @@ -71,7 +71,7 @@ func (kv *KVStore[ index uint64, amount math.Gwei, ) error { - return kv.slashings.Set(kv.ctx, index, uint64(amount)) + return kv.slashings.Set(kv.ctx, index, amount.Unwrap()) } // GetTotalSlashing retrieves the total slashing amount from the store. @@ -95,5 +95,5 @@ func (kv *KVStore[ ]) SetTotalSlashing( amount math.Gwei, ) error { - return kv.totalSlashing.Set(kv.ctx, uint64(amount)) + return kv.totalSlashing.Set(kv.ctx, amount.Unwrap()) } diff --git a/mod/storage/pkg/beacondb/versioning.go b/mod/storage/pkg/beacondb/versioning.go index a722c8395d..82d48e4456 100644 --- a/mod/storage/pkg/beacondb/versioning.go +++ b/mod/storage/pkg/beacondb/versioning.go @@ -65,5 +65,5 @@ func (kv *KVStore[ ]) SetSlot( slot math.Slot, ) error { - return kv.slot.Set(kv.ctx, uint64(slot)) + return kv.slot.Set(kv.ctx, slot.Unwrap()) } diff --git a/mod/storage/pkg/beacondb/withdrawals.go b/mod/storage/pkg/beacondb/withdrawals.go index 2a24872529..c9fc3faf4c 100644 --- a/mod/storage/pkg/beacondb/withdrawals.go +++ b/mod/storage/pkg/beacondb/withdrawals.go @@ -58,5 +58,5 @@ func (kv *KVStore[ ]) SetNextWithdrawalValidatorIndex( index math.ValidatorIndex, ) error { - return kv.nextWithdrawalValidatorIndex.Set(kv.ctx, uint64(index)) + return kv.nextWithdrawalValidatorIndex.Set(kv.ctx, index.Unwrap()) } diff --git a/mod/storage/pkg/deposit/store.go b/mod/storage/pkg/deposit/store.go index 2f1500bb97..1b8bb1e5e9 100644 --- a/mod/storage/pkg/deposit/store.go +++ b/mod/storage/pkg/deposit/store.go @@ -99,7 +99,7 @@ func (kv *KVStore[DepositT]) EnqueueDeposits(deposits []DepositT) error { // setDeposit sets the deposit in the store. func (kv *KVStore[DepositT]) setDeposit(deposit DepositT) error { - return kv.store.Set(context.TODO(), uint64(deposit.GetIndex()), deposit) + return kv.store.Set(context.TODO(), deposit.GetIndex().Unwrap(), deposit) } // Prune removes the [start, end) deposits from the store.