mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
Add new DomainType for application usage (#10740)
* Add new DomainType for application usage * Add DomainApplicationMask to config_test * Add func to convert uint32 to 4 byte array We add a convenience function Uint32ToBytes4 that takes a uint32, converts it to big endian order and return a 4 byte array. * Add unit test for Uint32ToBytes4 Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: terencechain <terence@prysmaticlabs.com>
This commit is contained in:
parent
051a83a83d
commit
c922eb9bfc
@ -123,6 +123,9 @@ func TestGetSpec(t *testing.T) {
|
||||
var daap [4]byte
|
||||
copy(daap[:], []byte{'0', '0', '0', '7'})
|
||||
config.DomainAggregateAndProof = daap
|
||||
var dam [4]byte
|
||||
copy(dam[:], []byte{'1', '0', '0', '0'})
|
||||
config.DomainApplicationMask = dam
|
||||
|
||||
params.OverrideBeaconConfig(config)
|
||||
|
||||
@ -130,7 +133,7 @@ func TestGetSpec(t *testing.T) {
|
||||
resp, err := server.GetSpec(context.Background(), &emptypb.Empty{})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, 98, len(resp.Data))
|
||||
assert.Equal(t, 99, len(resp.Data))
|
||||
for k, v := range resp.Data {
|
||||
switch k {
|
||||
case "CONFIG_NAME":
|
||||
@ -315,6 +318,8 @@ func TestGetSpec(t *testing.T) {
|
||||
assert.Equal(t, "0x30303036", v)
|
||||
case "DOMAIN_AGGREGATE_AND_PROOF":
|
||||
assert.Equal(t, "0x30303037", v)
|
||||
case "DOMAIN_APPLICATION_MASK":
|
||||
assert.Equal(t, "0x31303030", v)
|
||||
case "DOMAIN_SYNC_COMMITTEE":
|
||||
assert.Equal(t, "0x07000000", v)
|
||||
case "DOMAIN_SYNC_COMMITTEE_SELECTION_PROOF":
|
||||
|
@ -110,6 +110,7 @@ type BeaconChainConfig struct {
|
||||
DomainSyncCommittee [4]byte `yaml:"DOMAIN_SYNC_COMMITTEE" spec:"true"` // DomainVoluntaryExit defines the BLS signature domain for sync committee.
|
||||
DomainSyncCommitteeSelectionProof [4]byte `yaml:"DOMAIN_SYNC_COMMITTEE_SELECTION_PROOF" spec:"true"` // DomainSelectionProof defines the BLS signature domain for sync committee selection proof.
|
||||
DomainContributionAndProof [4]byte `yaml:"DOMAIN_CONTRIBUTION_AND_PROOF" spec:"true"` // DomainAggregateAndProof defines the BLS signature domain for contribution and proof.
|
||||
DomainApplicationMask [4]byte `yaml:"DOMAIN_APPLICATION_MASK" spec:"true"` // DomainApplicationMask defines the BLS signature domain for application mask.
|
||||
|
||||
// Prysm constants.
|
||||
GweiPerEth uint64 // GweiPerEth is the amount of gwei corresponding to 1 eth.
|
||||
|
@ -155,16 +155,17 @@ var mainnetBeaconConfig = &BeaconChainConfig{
|
||||
MaxVoluntaryExits: 16,
|
||||
|
||||
// BLS domain values.
|
||||
DomainBeaconProposer: bytesutil.ToBytes4(bytesutil.Bytes4(0)),
|
||||
DomainBeaconAttester: bytesutil.ToBytes4(bytesutil.Bytes4(1)),
|
||||
DomainRandao: bytesutil.ToBytes4(bytesutil.Bytes4(2)),
|
||||
DomainDeposit: bytesutil.ToBytes4(bytesutil.Bytes4(3)),
|
||||
DomainVoluntaryExit: bytesutil.ToBytes4(bytesutil.Bytes4(4)),
|
||||
DomainSelectionProof: bytesutil.ToBytes4(bytesutil.Bytes4(5)),
|
||||
DomainAggregateAndProof: bytesutil.ToBytes4(bytesutil.Bytes4(6)),
|
||||
DomainSyncCommittee: bytesutil.ToBytes4(bytesutil.Bytes4(7)),
|
||||
DomainSyncCommitteeSelectionProof: bytesutil.ToBytes4(bytesutil.Bytes4(8)),
|
||||
DomainContributionAndProof: bytesutil.ToBytes4(bytesutil.Bytes4(9)),
|
||||
DomainBeaconProposer: bytesutil.Uint32ToBytes4(0x00000000),
|
||||
DomainBeaconAttester: bytesutil.Uint32ToBytes4(0x01000000),
|
||||
DomainRandao: bytesutil.Uint32ToBytes4(0x02000000),
|
||||
DomainDeposit: bytesutil.Uint32ToBytes4(0x03000000),
|
||||
DomainVoluntaryExit: bytesutil.Uint32ToBytes4(0x04000000),
|
||||
DomainSelectionProof: bytesutil.Uint32ToBytes4(0x05000000),
|
||||
DomainAggregateAndProof: bytesutil.Uint32ToBytes4(0x06000000),
|
||||
DomainSyncCommittee: bytesutil.Uint32ToBytes4(0x07000000),
|
||||
DomainSyncCommitteeSelectionProof: bytesutil.Uint32ToBytes4(0x08000000),
|
||||
DomainContributionAndProof: bytesutil.Uint32ToBytes4(0x09000000),
|
||||
DomainApplicationMask: bytesutil.Uint32ToBytes4(0x00000001),
|
||||
|
||||
// Prysm constants.
|
||||
GweiPerEth: 1000000000,
|
||||
|
@ -339,6 +339,14 @@ func HighestBitIndexAt(b []byte, index int) (int, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// Uint32ToBytes4 is a convenience method for converting uint32 to a fix
|
||||
// sized 4 byte array in big endian order. Returns 4 byte array.
|
||||
func Uint32ToBytes4(i uint32) [4]byte {
|
||||
buf := make([]byte, 4)
|
||||
binary.BigEndian.PutUint32(buf, i)
|
||||
return ToBytes4(buf)
|
||||
}
|
||||
|
||||
// Uint64ToBytesLittleEndian conversion.
|
||||
func Uint64ToBytesLittleEndian(i uint64) []byte {
|
||||
buf := make([]byte, 8)
|
||||
|
@ -2,6 +2,7 @@ package bytesutil_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@ -582,3 +583,26 @@ func TestIsValidRoot(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUint32ToBytes4(t *testing.T) {
|
||||
tests := []struct {
|
||||
value uint32
|
||||
want [4]byte
|
||||
}{
|
||||
{
|
||||
value: 0x01000000,
|
||||
want: [4]byte{1, 0, 0, 0},
|
||||
},
|
||||
{
|
||||
value: 0x00000001,
|
||||
want: [4]byte{0, 0, 0, 1},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(fmt.Sprintf("0x%08x", tt.value), func(t *testing.T) {
|
||||
if got := bytesutil.Uint32ToBytes4(tt.value); !bytes.Equal(got[:], tt.want[:]) {
|
||||
t.Errorf("Uint32ToBytes4() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user