-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deposit receipts start index getters and setters (#13947)
* adding in getters and setters for deposit receipts start index * adding tests * gaz
- Loading branch information
1 parent
eed86c7
commit 5075f55
Showing
6 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
beacon-chain/state/state-native/getters_deposit_receipts.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package state_native | ||
|
||
import ( | ||
"github.com/prysmaticlabs/prysm/v5/runtime/version" | ||
) | ||
|
||
// DepositReceiptsStartIndex is used for returning the deposit receipts start index which is used for eip6110 | ||
func (b *BeaconState) DepositReceiptsStartIndex() (uint64, error) { | ||
if b.version < version.Electra { | ||
return 0, errNotSupported("DepositReceiptsStartIndex", b.version) | ||
} | ||
b.lock.RLock() | ||
defer b.lock.RUnlock() | ||
|
||
return b.depositReceiptsStartIndex, nil | ||
} |
26 changes: 26 additions & 0 deletions
26
beacon-chain/state/state-native/getters_deposit_receipts_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package state_native_test | ||
|
||
import ( | ||
"testing" | ||
|
||
state_native "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native" | ||
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" | ||
"github.com/prysmaticlabs/prysm/v5/testing/require" | ||
"github.com/prysmaticlabs/prysm/v5/testing/util" | ||
) | ||
|
||
func TestDepositReceiptsStartIndex(t *testing.T) { | ||
t.Run("previous fork returns expected error", func(t *testing.T) { | ||
dState, _ := util.DeterministicGenesisState(t, 1) | ||
_, err := dState.DepositReceiptsStartIndex() | ||
require.ErrorContains(t, "is not supported", err) | ||
}) | ||
t.Run("electra returns expected value", func(t *testing.T) { | ||
want := uint64(2) | ||
dState, err := state_native.InitializeFromProtoElectra(ðpb.BeaconStateElectra{DepositReceiptsStartIndex: want}) | ||
require.NoError(t, err) | ||
got, err := dState.DepositReceiptsStartIndex() | ||
require.NoError(t, err) | ||
require.Equal(t, want, got) | ||
}) | ||
} |
21 changes: 21 additions & 0 deletions
21
beacon-chain/state/state-native/setters_deposit_receipts.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package state_native | ||
|
||
import ( | ||
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native/types" | ||
"github.com/prysmaticlabs/prysm/v5/runtime/version" | ||
) | ||
|
||
// SetDepositReceiptsStartIndex for the beacon state. Updates the DepositReceiptsStartIndex | ||
func (b *BeaconState) SetDepositReceiptsStartIndex(index uint64) error { | ||
if b.version < version.Electra { | ||
return errNotSupported("SetDepositReceiptsStartIndex", b.version) | ||
} | ||
|
||
b.lock.Lock() | ||
defer b.lock.Unlock() | ||
|
||
b.depositReceiptsStartIndex = index | ||
b.markFieldAsDirty(types.DepositReceiptsStartIndex) | ||
b.rebuildTrie[types.DepositReceiptsStartIndex] = true | ||
return nil | ||
} |
27 changes: 27 additions & 0 deletions
27
beacon-chain/state/state-native/setters_deposit_receipts_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package state_native_test | ||
|
||
import ( | ||
"testing" | ||
|
||
state_native "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native" | ||
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" | ||
"github.com/prysmaticlabs/prysm/v5/testing/require" | ||
"github.com/prysmaticlabs/prysm/v5/testing/util" | ||
) | ||
|
||
func TestSetDepositReceiptsStartIndex(t *testing.T) { | ||
t.Run("previous fork returns expected error", func(t *testing.T) { | ||
dState, _ := util.DeterministicGenesisState(t, 1) | ||
require.ErrorContains(t, "is not supported", dState.SetDepositReceiptsStartIndex(1)) | ||
}) | ||
t.Run("electra sets expected value", func(t *testing.T) { | ||
old := uint64(2) | ||
dState, err := state_native.InitializeFromProtoElectra(ðpb.BeaconStateElectra{DepositReceiptsStartIndex: old}) | ||
require.NoError(t, err) | ||
want := uint64(3) | ||
require.NoError(t, dState.SetDepositReceiptsStartIndex(want)) | ||
got, err := dState.DepositReceiptsStartIndex() | ||
require.NoError(t, err) | ||
require.Equal(t, want, got) | ||
}) | ||
} |