Skip to content

Commit db74a7d

Browse files
AKorpusenkoy0sherMatusKysel
authored
optimization: (eventsyncer) don't remove QBFT instances to speed up historical syncing (#1615)
* optimize badger delete action * try another optimization * use dropprefix instead of delete all keys * drop messages only when own share or fullnode * removed usage of store.CleanAllInstances * remove storageMap from eventhandler --------- Co-authored-by: y0sher <[email protected]> Co-authored-by: Matus Kysel <[email protected]>
1 parent 3fab56e commit db74a7d

File tree

13 files changed

+12
-55
lines changed

13 files changed

+12
-55
lines changed

cli/operator/node.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ var StartNodeCmd = &cobra.Command{
372372
logger,
373373
executionClient,
374374
validatorCtrl,
375-
storageMap,
376375
metricsReporter,
377376
networkConfig,
378377
nodeStorage,
@@ -645,7 +644,6 @@ func setupEventHandling(
645644
logger *zap.Logger,
646645
executionClient *executionclient.ExecutionClient,
647646
validatorCtrl validator.Controller,
648-
storageMap *ibftstorage.QBFTStores,
649647
metricsReporter metricsreporter.MetricsReporter,
650648
networkConfig networkconfig.NetworkConfig,
651649
nodeStorage operatorstorage.Storage,
@@ -669,7 +667,6 @@ func setupEventHandling(
669667
operatorDecrypter,
670668
keyManager,
671669
cfg.SSVOptions.ValidatorOptions.Beacon,
672-
storageMap,
673670
eventhandler.WithFullNode(),
674671
eventhandler.WithLogger(logger),
675672
eventhandler.WithMetrics(metricsReporter),

eth/ethtest/utils_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ func setupEventHandler(
190190
operator.privateKey,
191191
keyManager,
192192
bc,
193-
storageMap,
194193
eventhandler.WithFullNode(),
195194
eventhandler.WithLogger(logger),
196195
)
@@ -222,7 +221,6 @@ func setupEventHandler(
222221
operator.privateKey,
223222
keyManager,
224223
bc,
225-
storageMap,
226224
eventhandler.WithFullNode(),
227225
eventhandler.WithLogger(logger),
228226
)

eth/eventhandler/event_handler.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ package eventhandler
55
import (
66
"errors"
77
"fmt"
8-
"github.com/ssvlabs/ssv/ekm"
98
"math/big"
109
"time"
1110

11+
"github.com/ssvlabs/ssv/ekm"
12+
1213
"github.com/attestantio/go-eth2-client/spec/phase0"
1314
ethcommon "github.com/ethereum/go-ethereum/common"
1415
ethtypes "github.com/ethereum/go-ethereum/core/types"
@@ -19,7 +20,6 @@ import (
1920
"github.com/ssvlabs/ssv/eth/eventparser"
2021
"github.com/ssvlabs/ssv/eth/executionclient"
2122
"github.com/ssvlabs/ssv/eth/localevents"
22-
qbftstorage "github.com/ssvlabs/ssv/ibft/storage"
2323
"github.com/ssvlabs/ssv/logging/fields"
2424
"github.com/ssvlabs/ssv/networkconfig"
2525
operatordatastore "github.com/ssvlabs/ssv/operator/datastore"
@@ -66,7 +66,6 @@ type EventHandler struct {
6666
operatorDecrypter keys.OperatorDecrypter
6767
keyManager ekm.KeyManager
6868
beacon beaconprotocol.BeaconNode
69-
storageMap *qbftstorage.QBFTStores
7069

7170
fullNode bool
7271
logger *zap.Logger
@@ -82,7 +81,6 @@ func New(
8281
operatorDecrypter keys.OperatorDecrypter,
8382
keyManager ekm.KeyManager,
8483
beacon beaconprotocol.BeaconNode,
85-
storageMap *qbftstorage.QBFTStores,
8684
opts ...Option,
8785
) (*EventHandler, error) {
8886
eh := &EventHandler{
@@ -94,7 +92,6 @@ func New(
9492
operatorDecrypter: operatorDecrypter,
9593
keyManager: keyManager,
9694
beacon: beacon,
97-
storageMap: storageMap,
9895
logger: zap.NewNop(),
9996
metrics: nopMetrics{},
10097
}

eth/eventhandler/event_handler_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,6 @@ func setupEventHandler(t *testing.T, ctx context.Context, logger *zap.Logger, ne
13241324
operator.privateKey,
13251325
keyManager,
13261326
bc,
1327-
storageMap,
13281327
WithFullNode(),
13291328
WithLogger(logger),
13301329
WithMetrics(nopMetrics{}),
@@ -1363,7 +1362,6 @@ func setupEventHandler(t *testing.T, ctx context.Context, logger *zap.Logger, ne
13631362
operator.privateKey,
13641363
keyManager,
13651364
bc,
1366-
storageMap,
13671365
WithFullNode(),
13681366
WithLogger(logger))
13691367
if err != nil {

eth/eventhandler/handlers.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ import (
1414

1515
"github.com/ssvlabs/ssv/ekm"
1616
"github.com/ssvlabs/ssv/eth/contract"
17-
"github.com/ssvlabs/ssv/exporter/convert"
1817
"github.com/ssvlabs/ssv/logging/fields"
1918
"github.com/ssvlabs/ssv/operator/duties"
20-
qbftstorage "github.com/ssvlabs/ssv/protocol/v2/qbft/storage"
2119
ssvtypes "github.com/ssvlabs/ssv/protocol/v2/types"
2220
registrystorage "github.com/ssvlabs/ssv/registry/storage"
2321
"github.com/ssvlabs/ssv/storage/basedb"
@@ -360,15 +358,6 @@ func (eh *EventHandler) handleValidatorRemoved(txn basedb.Txn, event *contract.C
360358
return emptyPK, &MalformedEventError{Err: ErrShareBelongsToDifferentOwner}
361359
}
362360

363-
removeDecidedMessages := func(role convert.RunnerRole, store qbftstorage.QBFTStore) error {
364-
messageID := convert.NewMsgID(eh.networkConfig.DomainType(), share.ValidatorPubKey[:], role)
365-
return store.CleanAllInstances(logger, messageID[:])
366-
}
367-
err := eh.storageMap.Each(removeDecidedMessages)
368-
if err != nil {
369-
return emptyPK, fmt.Errorf("could not clean all decided messages: %w", err)
370-
}
371-
372361
if err := eh.nodeStorage.Shares().Delete(txn, share.ValidatorPubKey[:]); err != nil {
373362
return emptyPK, fmt.Errorf("could not remove validator share: %w", err)
374363
}
@@ -378,7 +367,7 @@ func (eh *EventHandler) handleValidatorRemoved(txn basedb.Txn, event *contract.C
378367
logger = logger.With(zap.String("validator_pubkey", hex.EncodeToString(share.ValidatorPubKey[:])))
379368
}
380369
if isOperatorShare {
381-
err = eh.keyManager.RemoveShare(hex.EncodeToString(share.SharePubKey))
370+
err := eh.keyManager.RemoveShare(hex.EncodeToString(share.SharePubKey))
382371
if err != nil {
383372
return emptyPK, fmt.Errorf("could not remove share from ekm storage: %w", err)
384373
}

eth/eventsyncer/event_syncer_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"github.com/ssvlabs/ssv/eth/executionclient"
2828
"github.com/ssvlabs/ssv/eth/simulator"
2929
"github.com/ssvlabs/ssv/eth/simulator/simcontract"
30-
ibftstorage "github.com/ssvlabs/ssv/ibft/storage"
3130
"github.com/ssvlabs/ssv/networkconfig"
3231
operatordatastore "github.com/ssvlabs/ssv/operator/datastore"
3332
"github.com/ssvlabs/ssv/operator/keys"
@@ -152,7 +151,6 @@ func setupEventHandler(
152151
operatorData *registrystorage.OperatorData,
153152
privateKey keys.OperatorPrivateKey,
154153
) *eventhandler.EventHandler {
155-
storageMap := ibftstorage.NewStores()
156154
operatorDataStore := operatordatastore.New(operatorData)
157155
testNetworkConfig := networkconfig.TestNetwork
158156

@@ -187,7 +185,6 @@ func setupEventHandler(
187185
privateKey,
188186
keyManager,
189187
bc,
190-
storageMap,
191188
eventhandler.WithFullNode(),
192189
eventhandler.WithLogger(logger))
193190

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/btcsuite/btcd/btcec/v2 v2.3.2
1010
github.com/cespare/xxhash/v2 v2.3.0
1111
github.com/cornelk/hashmap v1.0.8
12-
github.com/dgraph-io/badger/v4 v4.1.0
12+
github.com/dgraph-io/badger/v4 v4.2.0
1313
github.com/dgraph-io/ristretto v0.1.1
1414
github.com/ethereum/go-ethereum v1.13.15
1515
github.com/ferranbt/fastssz v0.1.3

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3
139139
github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4=
140140
github.com/dgraph-io/badger/v4 v4.1.0 h1:E38jc0f+RATYrycSUf9LMv/t47XAy+3CApyYSq4APOQ=
141141
github.com/dgraph-io/badger/v4 v4.1.0/go.mod h1:P50u28d39ibBRmIJuQC/NSdBOg46HnHw7al2SW5QRHg=
142+
github.com/dgraph-io/badger/v4 v4.2.0 h1:kJrlajbXXL9DFTNuhhu9yCx7JJa4qpYWxtE8BzuWsEs=
143+
github.com/dgraph-io/badger/v4 v4.2.0/go.mod h1:qfCqhPoWDFJRx1gp5QwwyGo8xk1lbHUxvK9nK0OGAak=
142144
github.com/dgraph-io/ristretto v0.1.1-0.20211108053508-297c39e6640f h1:NBGp2JpfMtXmanFWt6f3gEdBtnLO5LupRvm3w4TXrvs=
143145
github.com/dgraph-io/ristretto v0.1.1-0.20211108053508-297c39e6640f/go.mod h1:fux0lOrBhrVCJd3lcTHsIJhq1T2rokOu6v9Vcb3Q9ug=
144146
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA=

ibft/genesisstorage/store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func (i *ibftStorage) CleanAllInstances(logger *zap.Logger, msgID []byte) error
140140
prefix := i.prefix
141141
prefix = append(prefix, msgID[:]...)
142142
prefix = append(prefix, []byte(instanceKey)...)
143-
_, err := i.db.DeletePrefix(prefix)
143+
err := i.db.DropPrefix(prefix)
144144
if err != nil {
145145
return errors.Wrap(err, "failed to remove decided")
146146
}

ibft/storage/store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (i *ibftStorage) CleanAllInstances(logger *zap.Logger, msgID []byte) error
143143
prefix := i.prefix
144144
prefix = append(prefix, msgID[:]...)
145145
prefix = append(prefix, []byte(instanceKey)...)
146-
_, err := i.db.DeletePrefix(prefix)
146+
err := i.db.DropPrefix(prefix)
147147
if err != nil {
148148
return errors.Wrap(err, "failed to remove decided")
149149
}

0 commit comments

Comments
 (0)