Skip to content

Commit

Permalink
chore(consensus-types): Make slashings use math.Gwei (#2038)
Browse files Browse the repository at this point in the history
  • Loading branch information
abi87 authored Oct 3, 2024
1 parent 88fe7a0 commit 455762b
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions mod/consensus-types/pkg/types/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type BeaconState[
NextWithdrawalValidatorIndex math.ValidatorIndex

// Slashing
Slashings []uint64
Slashings []math.Gwei
TotalSlashing math.Gwei
}

Expand Down Expand Up @@ -97,7 +97,7 @@ func (st *BeaconState[
randaoMixes []common.Bytes32,
nextWithdrawalIndex uint64,
nextWithdrawalValidatorIndex math.ValidatorIndex,
slashings []uint64,
slashings []math.Gwei,
totalSlashing math.Gwei,
) (*BeaconState[
BeaconBlockHeaderT,
Expand Down Expand Up @@ -378,7 +378,7 @@ func (st *BeaconState[
}
subIndx = hh.Index()
for _, i := range st.Slashings {
hh.AppendUint64(i)
hh.AppendUint64(uint64(i))
}
hh.FillUpTo32()
numItems = uint64(len(st.Slashings))
Expand Down
2 changes: 1 addition & 1 deletion mod/consensus-types/pkg/types/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func generateValidBeaconState() *types.BeaconState[
},
Balances: []uint64{32000000000, 31000000000},
RandaoMixes: generateRandomBytes32(65536),
Slashings: []uint64{1000000000, 2000000000},
Slashings: []math.Gwei{1000000000, 2000000000},
NextWithdrawalIndex: 7,
NextWithdrawalValidatorIndex: 8,
TotalSlashing: 3000000000,
Expand Down
2 changes: 1 addition & 1 deletion mod/node-api/handlers/proof/merkle/mock/beacon_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func NewBeaconState(
[]common.Bytes32{},
0,
0,
[]uint64{},
[]math.Gwei{},
0,
)
return &BeaconState{BeaconStateMarshallable: bsm}, err
Expand Down
4 changes: 2 additions & 2 deletions mod/node-core/pkg/components/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ type (
randaoMixes []common.Bytes32,
nextWithdrawalIndex uint64,
nextWithdrawalValidatorIndex math.U64,
slashings []uint64, totalSlashing math.U64,
slashings []math.U64, totalSlashing math.U64,
) (T, error)
}

Expand Down Expand Up @@ -894,7 +894,7 @@ type (
// GetRandaoMixAtIndex retrieves the randao mix at the given index.
GetRandaoMixAtIndex(index uint64) (common.Bytes32, error)
// GetSlashings retrieves all slashings.
GetSlashings() ([]uint64, error)
GetSlashings() ([]math.Gwei, error)
// SetSlashingAtIndex sets the slashing at the given index.
SetSlashingAtIndex(index uint64, amount math.Gwei) error
// GetSlashingAtIndex retrieves the slashing at the given index.
Expand Down
2 changes: 1 addition & 1 deletion mod/state-transition/pkg/core/state/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ type KVStore[
// GetRandaoMixAtIndex retrieves the randao mix at the given index.
GetRandaoMixAtIndex(index uint64) (common.Bytes32, error)
// GetSlashings retrieves all slashings.
GetSlashings() ([]uint64, error)
GetSlashings() ([]math.Gwei, error)
// SetSlashingAtIndex sets the slashing at the given index.
SetSlashingAtIndex(index uint64, amount math.Gwei) error
// GetSlashingAtIndex retrieves the slashing at the given index.
Expand Down
2 changes: 1 addition & 1 deletion mod/state-transition/pkg/core/state/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type BeaconStateMarshallable[
randaoMixes []common.Bytes32,
nextWithdrawalIndex uint64,
nextWithdrawalValidatorIndex math.U64,
slashings []uint64, totalSlashing math.U64,
slashings []math.U64, totalSlashing math.U64,
) (T, error)
}

Expand Down
6 changes: 3 additions & 3 deletions mod/storage/pkg/beacondb/slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
func (kv *KVStore[
BeaconBlockHeaderT, Eth1DataT, ExecutionPayloadHeaderT,
ForkT, ValidatorT, ValidatorsT,
]) GetSlashings() ([]uint64, error) {
var slashings []uint64
]) GetSlashings() ([]math.Gwei, error) {
var slashings []math.Gwei
iter, err := kv.slashings.Iterate(kv.ctx, nil)
if err != nil {
return nil, err
Expand All @@ -41,7 +41,7 @@ func (kv *KVStore[
if err != nil {
return nil, err
}
slashings = append(slashings, slashing)
slashings = append(slashings, math.Gwei(slashing))
iter.Next()
}
return slashings, nil
Expand Down

0 comments on commit 455762b

Please sign in to comment.