|
9 | 9 | "github.com/prysmaticlabs/go-bitfield"
|
10 | 10 | "github.com/prysmaticlabs/prysm/v4/beacon-chain/state"
|
11 | 11 | "github.com/prysmaticlabs/prysm/v4/beacon-chain/state/state-native/types"
|
| 12 | + "github.com/prysmaticlabs/prysm/v4/config/features" |
12 | 13 | "github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
|
13 | 14 | ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
14 | 15 | "github.com/prysmaticlabs/prysm/v4/testing/assert"
|
@@ -1015,6 +1016,43 @@ func TestValidatorReferences_RemainsConsistent_Bellatrix(t *testing.T) {
|
1015 | 1016 | }))
|
1016 | 1017 | }
|
1017 | 1018 |
|
| 1019 | +func TestValidatorReferences_ApplyValidator_BalancesRead(t *testing.T) { |
| 1020 | + resetCfg := features.InitWithReset(&features.Flags{ |
| 1021 | + EnableExperimentalState: true, |
| 1022 | + }) |
| 1023 | + defer resetCfg() |
| 1024 | + s, err := InitializeFromProtoUnsafeAltair(ðpb.BeaconStateAltair{ |
| 1025 | + Validators: []*ethpb.Validator{ |
| 1026 | + {PublicKey: []byte{'A'}}, |
| 1027 | + {PublicKey: []byte{'B'}}, |
| 1028 | + {PublicKey: []byte{'C'}}, |
| 1029 | + {PublicKey: []byte{'D'}}, |
| 1030 | + {PublicKey: []byte{'E'}}, |
| 1031 | + }, |
| 1032 | + Balances: []uint64{0, 0, 0, 0, 0}, |
| 1033 | + }) |
| 1034 | + require.NoError(t, err) |
| 1035 | + a, ok := s.(*BeaconState) |
| 1036 | + require.Equal(t, true, ok) |
| 1037 | + |
| 1038 | + // Create a second state. |
| 1039 | + copied := a.Copy() |
| 1040 | + b, ok := copied.(*BeaconState) |
| 1041 | + require.Equal(t, true, ok) |
| 1042 | + |
| 1043 | + // Modify all validators from copied state, it should not deadlock. |
| 1044 | + assert.NoError(t, b.ApplyToEveryValidator(func(idx int, val *ethpb.Validator) (bool, *ethpb.Validator, error) { |
| 1045 | + b, err := b.BalanceAtIndex(0) |
| 1046 | + if err != nil { |
| 1047 | + return false, nil, err |
| 1048 | + } |
| 1049 | + newVal := ethpb.CopyValidator(val) |
| 1050 | + newVal.EffectiveBalance += b |
| 1051 | + val.EffectiveBalance += b |
| 1052 | + return true, val, nil |
| 1053 | + })) |
| 1054 | +} |
| 1055 | + |
1018 | 1056 | // assertRefCount checks whether reference count for a given state
|
1019 | 1057 | // at a given index is equal to expected amount.
|
1020 | 1058 | func assertRefCount(t *testing.T, b *BeaconState, idx types.FieldIndex, want uint) {
|
|
0 commit comments