Skip to content

Commit c07479b

Browse files
authored
remove error return from HistoricalRoots (#15255)
* remove error return from HistoricalRoots * Radek's review
1 parent 0d3b7f0 commit c07479b

File tree

17 files changed

+36
-97
lines changed

17 files changed

+36
-97
lines changed

api/server/structs/conversions_state.go

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ func BeaconStateFromConsensus(st beaconState.BeaconState) (*BeaconState, error)
2626
for i, r := range srcSr {
2727
sr[i] = hexutil.Encode(r)
2828
}
29-
srcHr, err := st.HistoricalRoots()
30-
if err != nil {
31-
return nil, err
32-
}
29+
srcHr := st.HistoricalRoots()
3330
hr := make([]string, len(srcHr))
3431
for i, r := range srcHr {
3532
hr[i] = hexutil.Encode(r)
@@ -116,10 +113,7 @@ func BeaconStateAltairFromConsensus(st beaconState.BeaconState) (*BeaconStateAlt
116113
for i, r := range srcSr {
117114
sr[i] = hexutil.Encode(r)
118115
}
119-
srcHr, err := st.HistoricalRoots()
120-
if err != nil {
121-
return nil, err
122-
}
116+
srcHr := st.HistoricalRoots()
123117
hr := make([]string, len(srcHr))
124118
for i, r := range srcHr {
125119
hr[i] = hexutil.Encode(r)
@@ -225,10 +219,7 @@ func BeaconStateBellatrixFromConsensus(st beaconState.BeaconState) (*BeaconState
225219
for i, r := range srcSr {
226220
sr[i] = hexutil.Encode(r)
227221
}
228-
srcHr, err := st.HistoricalRoots()
229-
if err != nil {
230-
return nil, err
231-
}
222+
srcHr := st.HistoricalRoots()
232223
hr := make([]string, len(srcHr))
233224
for i, r := range srcHr {
234225
hr[i] = hexutil.Encode(r)
@@ -347,10 +338,7 @@ func BeaconStateCapellaFromConsensus(st beaconState.BeaconState) (*BeaconStateCa
347338
for i, r := range srcSr {
348339
sr[i] = hexutil.Encode(r)
349340
}
350-
srcHr, err := st.HistoricalRoots()
351-
if err != nil {
352-
return nil, err
353-
}
341+
srcHr := st.HistoricalRoots()
354342
hr := make([]string, len(srcHr))
355343
for i, r := range srcHr {
356344
hr[i] = hexutil.Encode(r)
@@ -488,10 +476,7 @@ func BeaconStateDenebFromConsensus(st beaconState.BeaconState) (*BeaconStateDene
488476
for i, r := range srcSr {
489477
sr[i] = hexutil.Encode(r)
490478
}
491-
srcHr, err := st.HistoricalRoots()
492-
if err != nil {
493-
return nil, err
494-
}
479+
srcHr := st.HistoricalRoots()
495480
hr := make([]string, len(srcHr))
496481
for i, r := range srcHr {
497482
hr[i] = hexutil.Encode(r)
@@ -629,10 +614,7 @@ func BeaconStateElectraFromConsensus(st beaconState.BeaconState) (*BeaconStateEl
629614
for i, r := range srcSr {
630615
sr[i] = hexutil.Encode(r)
631616
}
632-
srcHr, err := st.HistoricalRoots()
633-
if err != nil {
634-
return nil, err
635-
}
617+
srcHr := st.HistoricalRoots()
636618
hr := make([]string, len(srcHr))
637619
for i, r := range srcHr {
638620
hr[i] = hexutil.Encode(r)
@@ -815,10 +797,7 @@ func BeaconStateFuluFromConsensus(st beaconState.BeaconState) (*BeaconStateFulu,
815797
for i, r := range srcSr {
816798
sr[i] = hexutil.Encode(r)
817799
}
818-
srcHr, err := st.HistoricalRoots()
819-
if err != nil {
820-
return nil, err
821-
}
800+
srcHr := st.HistoricalRoots()
822801
hr := make([]string, len(srcHr))
823802
for i, r := range srcHr {
824803
hr[i] = hexutil.Encode(r)

beacon-chain/core/altair/upgrade.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ func UpgradeToAltair(ctx context.Context, state state.BeaconState) (state.Beacon
6767
epoch := time.CurrentEpoch(state)
6868

6969
numValidators := state.NumValidators()
70-
hrs, err := state.HistoricalRoots()
71-
if err != nil {
72-
return nil, err
73-
}
7470
s := &ethpb.BeaconStateAltair{
7571
GenesisTime: state.GenesisTime(),
7672
GenesisValidatorsRoot: state.GenesisValidatorsRoot(),
@@ -83,7 +79,7 @@ func UpgradeToAltair(ctx context.Context, state state.BeaconState) (state.Beacon
8379
LatestBlockHeader: state.LatestBlockHeader(),
8480
BlockRoots: state.BlockRoots(),
8581
StateRoots: state.StateRoots(),
86-
HistoricalRoots: hrs,
82+
HistoricalRoots: state.HistoricalRoots(),
8783
Eth1Data: state.Eth1Data(),
8884
Eth1DataVotes: state.Eth1DataVotes(),
8985
Eth1DepositIndex: state.Eth1DepositIndex(),

beacon-chain/core/altair/upgrade_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,8 @@ func TestUpgradeToAltair(t *testing.T) {
8282
require.DeepSSZEqual(t, preForkState.LatestBlockHeader(), aState.LatestBlockHeader())
8383
require.DeepSSZEqual(t, preForkState.BlockRoots(), aState.BlockRoots())
8484
require.DeepSSZEqual(t, preForkState.StateRoots(), aState.StateRoots())
85-
r1, err := preForkState.HistoricalRoots()
86-
require.NoError(t, err)
87-
r2, err := aState.HistoricalRoots()
88-
require.NoError(t, err)
85+
r1 := preForkState.HistoricalRoots()
86+
r2 := aState.HistoricalRoots()
8987
require.DeepSSZEqual(t, r1, r2)
9088
require.DeepSSZEqual(t, preForkState.Eth1Data(), aState.Eth1Data())
9189
require.DeepSSZEqual(t, preForkState.Eth1DataVotes(), aState.Eth1DataVotes())

beacon-chain/core/capella/upgrade.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ func UpgradeToCapella(state state.BeaconState) (state.BeaconState, error) {
4242
return nil, err
4343
}
4444

45-
hrs, err := state.HistoricalRoots()
46-
if err != nil {
47-
return nil, err
48-
}
4945
s := &ethpb.BeaconStateCapella{
5046
GenesisTime: state.GenesisTime(),
5147
GenesisValidatorsRoot: state.GenesisValidatorsRoot(),
@@ -58,7 +54,7 @@ func UpgradeToCapella(state state.BeaconState) (state.BeaconState, error) {
5854
LatestBlockHeader: state.LatestBlockHeader(),
5955
BlockRoots: state.BlockRoots(),
6056
StateRoots: state.StateRoots(),
61-
HistoricalRoots: hrs,
57+
HistoricalRoots: state.HistoricalRoots(),
6258
Eth1Data: state.Eth1Data(),
6359
Eth1DataVotes: state.Eth1DataVotes(),
6460
Eth1DepositIndex: state.Eth1DepositIndex(),

beacon-chain/core/deneb/upgrade.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ func UpgradeToDeneb(state state.BeaconState) (state.BeaconState, error) {
5757
if err != nil {
5858
return nil, err
5959
}
60-
historicalRoots, err := state.HistoricalRoots()
61-
if err != nil {
62-
return nil, err
63-
}
6460

6561
s := &ethpb.BeaconStateDeneb{
6662
GenesisTime: state.GenesisTime(),
@@ -74,7 +70,7 @@ func UpgradeToDeneb(state state.BeaconState) (state.BeaconState, error) {
7470
LatestBlockHeader: state.LatestBlockHeader(),
7571
BlockRoots: state.BlockRoots(),
7672
StateRoots: state.StateRoots(),
77-
HistoricalRoots: historicalRoots,
73+
HistoricalRoots: state.HistoricalRoots(),
7874
Eth1Data: state.Eth1Data(),
7975
Eth1DataVotes: state.Eth1DataVotes(),
8076
Eth1DepositIndex: state.Eth1DepositIndex(),

beacon-chain/core/deneb/upgrade_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,8 @@ func TestUpgradeToDeneb(t *testing.T) {
4747
require.NoError(t, err)
4848
require.DeepSSZEqual(t, make([]uint64, numValidators), s)
4949

50-
hr1, err := preForkState.HistoricalRoots()
51-
require.NoError(t, err)
52-
hr2, err := mSt.HistoricalRoots()
53-
require.NoError(t, err)
50+
hr1 := preForkState.HistoricalRoots()
51+
hr2 := mSt.HistoricalRoots()
5452
require.DeepEqual(t, hr1, hr2)
5553

5654
f := mSt.Fork()

beacon-chain/core/electra/upgrade.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,6 @@ func UpgradeToElectra(beaconState state.BeaconState) (state.BeaconState, error)
170170
if err != nil {
171171
return nil, err
172172
}
173-
historicalRoots, err := beaconState.HistoricalRoots()
174-
if err != nil {
175-
return nil, err
176-
}
177173
excessBlobGas, err := payloadHeader.ExcessBlobGas()
178174
if err != nil {
179175
return nil, err
@@ -223,7 +219,7 @@ func UpgradeToElectra(beaconState state.BeaconState) (state.BeaconState, error)
223219
LatestBlockHeader: beaconState.LatestBlockHeader(),
224220
BlockRoots: beaconState.BlockRoots(),
225221
StateRoots: beaconState.StateRoots(),
226-
HistoricalRoots: historicalRoots,
222+
HistoricalRoots: beaconState.HistoricalRoots(),
227223
Eth1Data: beaconState.Eth1Data(),
228224
Eth1DataVotes: beaconState.Eth1DataVotes(),
229225
Eth1DepositIndex: beaconState.Eth1DepositIndex(),

beacon-chain/core/electra/upgrade_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,8 @@ func TestUpgradeToElectra(t *testing.T) {
7777
require.NoError(t, err)
7878
require.DeepSSZEqual(t, make([]uint64, numValidators), s)
7979

80-
hr1, err := preForkState.HistoricalRoots()
81-
require.NoError(t, err)
82-
hr2, err := mSt.HistoricalRoots()
83-
require.NoError(t, err)
80+
hr1 := preForkState.HistoricalRoots()
81+
hr2 := mSt.HistoricalRoots()
8482
require.DeepEqual(t, hr1, hr2)
8583

8684
f := mSt.Fork()

beacon-chain/core/epoch/epoch_processing_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ func TestProcessFinalUpdates_CanProcess(t *testing.T) {
148148
assert.DeepNotEqual(t, params.BeaconConfig().ZeroHash[:], mix, "latest RANDAO still zero hashes")
149149

150150
// Verify historical root accumulator was appended.
151-
roots, err := newS.HistoricalRoots()
152-
require.NoError(t, err)
151+
roots := newS.HistoricalRoots()
153152
assert.Equal(t, 1, len(roots), "Unexpected slashed balance")
154153
currAtt, err := newS.CurrentEpochAttestations()
155154
require.NoError(t, err)
@@ -379,8 +378,7 @@ func TestProcessHistoricalDataUpdate(t *testing.T) {
379378
return st
380379
},
381380
verifier: func(st state.BeaconState) {
382-
roots, err := st.HistoricalRoots()
383-
require.NoError(t, err)
381+
roots := st.HistoricalRoots()
384382
require.Equal(t, 0, len(roots))
385383
},
386384
},
@@ -393,8 +391,7 @@ func TestProcessHistoricalDataUpdate(t *testing.T) {
393391
return st
394392
},
395393
verifier: func(st state.BeaconState) {
396-
roots, err := st.HistoricalRoots()
397-
require.NoError(t, err)
394+
roots := st.HistoricalRoots()
398395
require.Equal(t, 1, len(roots))
399396

400397
b := &ethpb.HistoricalBatch{
@@ -431,8 +428,7 @@ func TestProcessHistoricalDataUpdate(t *testing.T) {
431428
StateSummaryRoot: sr[:],
432429
}
433430
require.DeepEqual(t, b, summaries[0])
434-
hrs, err := st.HistoricalRoots()
435-
require.NoError(t, err)
431+
hrs := st.HistoricalRoots()
436432
require.DeepEqual(t, hrs, [][]byte{})
437433
},
438434
},

beacon-chain/core/execution/upgrade.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ func UpgradeToBellatrix(state state.BeaconState) (state.BeaconState, error) {
3535
return nil, err
3636
}
3737

38-
hrs, err := state.HistoricalRoots()
39-
if err != nil {
40-
return nil, err
41-
}
4238
s := &ethpb.BeaconStateBellatrix{
4339
GenesisTime: state.GenesisTime(),
4440
GenesisValidatorsRoot: state.GenesisValidatorsRoot(),
@@ -51,7 +47,7 @@ func UpgradeToBellatrix(state state.BeaconState) (state.BeaconState, error) {
5147
LatestBlockHeader: state.LatestBlockHeader(),
5248
BlockRoots: state.BlockRoots(),
5349
StateRoots: state.StateRoots(),
54-
HistoricalRoots: hrs,
50+
HistoricalRoots: state.HistoricalRoots(),
5551
Eth1Data: state.Eth1Data(),
5652
Eth1DataVotes: state.Eth1DataVotes(),
5753
Eth1DepositIndex: state.Eth1DepositIndex(),

0 commit comments

Comments
 (0)