@@ -12,8 +12,10 @@ import (
12
12
"github.com/ethereum/go-ethereum/common"
13
13
gethtypes "github.com/ethereum/go-ethereum/core/types"
14
14
"github.com/pkg/errors"
15
+ "github.com/prysmaticlabs/go-bitfield"
15
16
"github.com/prysmaticlabs/prysm/v5/beacon-chain/cache"
16
17
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/blocks"
18
+ "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers"
17
19
lightClient "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/light-client"
18
20
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/signing"
19
21
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/transition"
@@ -25,6 +27,7 @@ import (
25
27
mockExecution "github.com/prysmaticlabs/prysm/v5/beacon-chain/execution/testing"
26
28
doublylinkedtree "github.com/prysmaticlabs/prysm/v5/beacon-chain/forkchoice/doubly-linked-tree"
27
29
forkchoicetypes "github.com/prysmaticlabs/prysm/v5/beacon-chain/forkchoice/types"
30
+ "github.com/prysmaticlabs/prysm/v5/beacon-chain/operations/attestations/kv"
28
31
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
29
32
"github.com/prysmaticlabs/prysm/v5/config/features"
30
33
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
@@ -45,6 +48,88 @@ import (
45
48
logTest "github.com/sirupsen/logrus/hooks/test"
46
49
)
47
50
51
+ func Test_pruneAttsFromPool_Electra (t * testing.T ) {
52
+ ctx := context .Background ()
53
+
54
+ params .SetupTestConfigCleanup (t )
55
+ cfg := params .BeaconConfig ().Copy ()
56
+ cfg .TargetCommitteeSize = 8
57
+ params .OverrideBeaconConfig (cfg )
58
+
59
+ s := Service {
60
+ cfg : & config {
61
+ AttPool : kv .NewAttCaches (),
62
+ },
63
+ }
64
+
65
+ data := & ethpb.AttestationData {
66
+ BeaconBlockRoot : make ([]byte , 32 ),
67
+ Source : & ethpb.Checkpoint {Root : make ([]byte , 32 )},
68
+ Target : & ethpb.Checkpoint {Root : make ([]byte , 32 )},
69
+ }
70
+
71
+ cb := primitives .NewAttestationCommitteeBits ()
72
+ cb .SetBitAt (0 , true )
73
+ att1 := & ethpb.AttestationElectra {
74
+ AggregationBits : bitfield.Bitlist {0b11110111 , 0b00000001 },
75
+ Data : data ,
76
+ Signature : make ([]byte , 96 ),
77
+ CommitteeBits : cb ,
78
+ }
79
+
80
+ cb = primitives .NewAttestationCommitteeBits ()
81
+ cb .SetBitAt (1 , true )
82
+ att2 := & ethpb.AttestationElectra {
83
+ AggregationBits : bitfield.Bitlist {0b11110111 , 0b00000001 },
84
+ Data : data ,
85
+ Signature : make ([]byte , 96 ),
86
+ CommitteeBits : cb ,
87
+ }
88
+
89
+ cb = primitives .NewAttestationCommitteeBits ()
90
+ cb .SetBitAt (3 , true )
91
+ att3 := & ethpb.AttestationElectra {
92
+ AggregationBits : bitfield.Bitlist {0b11110111 , 0b00000001 },
93
+ Data : data ,
94
+ Signature : make ([]byte , 96 ),
95
+ CommitteeBits : cb ,
96
+ }
97
+
98
+ require .NoError (t , s .cfg .AttPool .SaveAggregatedAttestation (att1 ))
99
+ require .NoError (t , s .cfg .AttPool .SaveAggregatedAttestation (att2 ))
100
+ require .NoError (t , s .cfg .AttPool .SaveAggregatedAttestation (att3 ))
101
+ require .Equal (t , 3 , len (s .cfg .AttPool .AggregatedAttestations ()))
102
+
103
+ cb = primitives .NewAttestationCommitteeBits ()
104
+ cb .SetBitAt (0 , true )
105
+ cb .SetBitAt (1 , true )
106
+ onChainAtt := & ethpb.AttestationElectra {
107
+ AggregationBits : bitfield.Bitlist {0b11110111 , 0b11110111 , 0b00000001 },
108
+ Data : data ,
109
+ Signature : make ([]byte , 96 ),
110
+ CommitteeBits : cb ,
111
+ }
112
+ bl := & ethpb.SignedBeaconBlockElectra {
113
+ Block : & ethpb.BeaconBlockElectra {
114
+ Body : & ethpb.BeaconBlockBodyElectra {
115
+ Attestations : []* ethpb.AttestationElectra {onChainAtt },
116
+ },
117
+ },
118
+ Signature : make ([]byte , 96 ),
119
+ }
120
+ rob , err := consensusblocks .NewSignedBeaconBlock (bl )
121
+ require .NoError (t , err )
122
+ st , _ := util .DeterministicGenesisStateElectra (t , 1024 )
123
+ committees , err := helpers .BeaconCommittees (ctx , st , 0 )
124
+ require .NoError (t , err )
125
+ require .Equal (t , 4 , len (committees ))
126
+
127
+ require .NoError (t , s .pruneAttsFromPool (ctx , st , rob ))
128
+ attsInPool := s .cfg .AttPool .AggregatedAttestations ()
129
+ require .Equal (t , 1 , len (attsInPool ))
130
+ assert .DeepEqual (t , att3 , attsInPool [0 ])
131
+ }
132
+
48
133
func TestStore_OnBlockBatch (t * testing.T ) {
49
134
service , tr := minimalTestService (t )
50
135
ctx := tr .ctx
@@ -840,7 +925,7 @@ func TestRemoveBlockAttestationsInPool(t *testing.T) {
840
925
require .NoError (t , service .cfg .AttPool .SaveAggregatedAttestations (atts ))
841
926
wsb , err := consensusblocks .NewSignedBeaconBlock (b )
842
927
require .NoError (t , err )
843
- require .NoError (t , service .pruneAttsFromPool (wsb ))
928
+ require .NoError (t , service .pruneAttsFromPool (context . Background (), nil /* state not needed pre-Electra */ , wsb ))
844
929
require .Equal (t , 0 , service .cfg .AttPool .AggregatedAttestationCount ())
845
930
}
846
931
0 commit comments