From 233c112eeb85adab9533f9abd37d2a7c112b46b0 Mon Sep 17 00:00:00 2001 From: pk910 Date: Fri, 23 Aug 2024 13:42:37 +0200 Subject: [PATCH 1/5] start mev indexer --- services/chainservice.go | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/services/chainservice.go b/services/chainservice.go index b7c56be..4bf0669 100644 --- a/services/chainservice.go +++ b/services/chainservice.go @@ -18,17 +18,19 @@ import ( "github.com/ethpandaops/dora/dbtypes" "github.com/ethpandaops/dora/indexer/beacon" execindexer "github.com/ethpandaops/dora/indexer/execution" + "github.com/ethpandaops/dora/indexer/mevrelay" "github.com/ethpandaops/dora/utils" "github.com/sirupsen/logrus" ) type ChainService struct { - logger logrus.FieldLogger - consensusPool *consensus.Pool - executionPool *execution.Pool - beaconIndexer *beacon.Indexer - validatorNames *ValidatorNames - started bool + logger logrus.FieldLogger + consensusPool *consensus.Pool + executionPool *execution.Pool + beaconIndexer *beacon.Indexer + validatorNames *ValidatorNames + mevRelayIndexer *mevrelay.MevIndexer + started bool } var GlobalBeaconService *ChainService @@ -43,14 +45,17 @@ func InitChainService(ctx context.Context, logger logrus.FieldLogger) { consensusPool := consensus.NewPool(ctx, logger.WithField("service", "cl-pool")) executionPool := execution.NewPool(ctx, logger.WithField("service", "el-pool")) beaconIndexer := beacon.NewIndexer(logger.WithField("service", "cl-indexer"), consensusPool) - validatorNames := NewValidatorNames(beaconIndexer, consensusPool.GetChainState()) + chainState := consensusPool.GetChainState() + validatorNames := NewValidatorNames(beaconIndexer, chainState) + mevRelayIndexer := mevrelay.NewMevIndexer(logger.WithField("service", "mev-relay"), beaconIndexer, chainState) GlobalBeaconService = &ChainService{ - logger: logger, - consensusPool: consensusPool, - executionPool: executionPool, - beaconIndexer: beaconIndexer, - validatorNames: validatorNames, + logger: logger, + consensusPool: consensusPool, + executionPool: executionPool, + beaconIndexer: beaconIndexer, + validatorNames: validatorNames, + mevRelayIndexer: mevRelayIndexer, } } @@ -176,6 +181,9 @@ func (cs *ChainService) StartService() error { // add execution indexers execindexer.NewDepositIndexer(executionIndexerCtx) + // start MEV relay indexer + cs.mevRelayIndexer.StartUpdater() + return nil } From 3d1f9c956aa237583ad6ce9f6eb3c56b8188f63c Mon Sep 17 00:00:00 2001 From: pk910 Date: Fri, 23 Aug 2024 13:46:08 +0200 Subject: [PATCH 2/5] trigger ci --- indexer/mevrelay/mevindexer.go | 1 + 1 file changed, 1 insertion(+) diff --git a/indexer/mevrelay/mevindexer.go b/indexer/mevrelay/mevindexer.go index ddc1e4b..37ef4d2 100644 --- a/indexer/mevrelay/mevindexer.go +++ b/indexer/mevrelay/mevindexer.go @@ -57,6 +57,7 @@ func (mev *MevIndexer) StartUpdater() { if mev.updaterRunning { return } + if utils.Config.MevIndexer.RefreshInterval == 0 { utils.Config.MevIndexer.RefreshInterval = 10 * time.Minute } From 1e3dcd21f2d84acf7ab4c605a0d6fb1e854d2984 Mon Sep 17 00:00:00 2001 From: pk910 Date: Fri, 23 Aug 2024 13:54:49 +0200 Subject: [PATCH 3/5] do not process mev blocks before latest canonical validator set is ready --- indexer/mevrelay/mevindexer.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/indexer/mevrelay/mevindexer.go b/indexer/mevrelay/mevindexer.go index 37ef4d2..6f8753f 100644 --- a/indexer/mevrelay/mevindexer.go +++ b/indexer/mevrelay/mevindexer.go @@ -246,14 +246,19 @@ func (mev *MevIndexer) loadMevBlocksFromRelay(relay *types.MevRelayConfig) error } // parse blocks - mev.mevBlockCacheMutex.Lock() - defer mev.mevBlockCacheMutex.Unlock() validatorSet := mev.beaconIndexer.GetCanonicalValidatorSet(nil) + if len(validatorSet) == 0 { + return fmt.Errorf("validator set is empty") + } + validatorMap := map[phase0.BLSPubKey]*v1.Validator{} for _, validator := range validatorSet { validatorMap[validator.Validator.PublicKey] = validator } + mev.mevBlockCacheMutex.Lock() + defer mev.mevBlockCacheMutex.Unlock() + finalizedEpoch, _ := mev.beaconIndexer.GetBlockCacheState() finalizedSlot := phase0.Slot(0) if finalizedEpoch > 0 { From 059190b0c75994248807c07ea71031c7c2cf6104 Mon Sep 17 00:00:00 2001 From: pk910 Date: Fri, 23 Aug 2024 13:56:51 +0200 Subject: [PATCH 4/5] fix typo on mev blocks page --- templates/mev_blocks/mev_blocks.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/mev_blocks/mev_blocks.html b/templates/mev_blocks/mev_blocks.html index 3fb6a89..f2f9d37 100644 --- a/templates/mev_blocks/mev_blocks.html +++ b/templates/mev_blocks/mev_blocks.html @@ -217,7 +217,7 @@

MEV Blocks

-
Showing voluntary exits from slot {{ .FirstIndex }} to {{ .LastIndex }}
+
Showing MEV blocks from slot {{ .FirstIndex }} to {{ .LastIndex }}
From b4444e9e6d7e1a1f569d09bf52ff7ef9a896024b Mon Sep 17 00:00:00 2001 From: pk910 Date: Fri, 23 Aug 2024 23:29:36 +0200 Subject: [PATCH 5/5] fix mev indexer --- indexer/beacon/finalization.go | 6 +++++- indexer/beacon/synchronizer.go | 6 +++++- indexer/mevrelay/mevindexer.go | 25 +++++++------------------ 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/indexer/beacon/finalization.go b/indexer/beacon/finalization.go index 4146efc..aeb51f9 100644 --- a/indexer/beacon/finalization.go +++ b/indexer/beacon/finalization.go @@ -291,8 +291,12 @@ func (indexer *Indexer) finalizeEpoch(epoch phase0.Epoch, justifiedRoot phase0.R } canonicalRoots := make([][]byte, len(canonicalBlocks)) + canonicalBlockHashes := make([][]byte, len(canonicalBlocks)) for i, block := range canonicalBlocks { canonicalRoots[i] = block.Root[:] + if blockIndex := block.GetBlockIndex(); blockIndex != nil { + canonicalBlockHashes[i] = blockIndex.ExecutionHash[:] + } } t1dur := time.Since(t1) - t1loading @@ -330,7 +334,7 @@ func (indexer *Indexer) finalizeEpoch(epoch phase0.Epoch, justifiedRoot phase0.R return fmt.Errorf("error persisting sync committee assignments to db: %v", err) } - if err := db.UpdateMevBlockByEpoch(uint64(epoch), specs.SlotsPerEpoch, canonicalRoots, tx); err != nil { + if err := db.UpdateMevBlockByEpoch(uint64(epoch), specs.SlotsPerEpoch, canonicalBlockHashes, tx); err != nil { return fmt.Errorf("error while updating mev block proposal state: %v", err) } diff --git a/indexer/beacon/synchronizer.go b/indexer/beacon/synchronizer.go index 6b7323e..8925eeb 100644 --- a/indexer/beacon/synchronizer.go +++ b/indexer/beacon/synchronizer.go @@ -280,6 +280,7 @@ func (sync *synchronizer) syncEpoch(syncEpoch phase0.Epoch, client *Client, last lastSlot := chainState.EpochStartSlot(syncEpoch+2) - 1 canonicalBlocks := []*Block{} canonicalBlockRoots := [][]byte{} + canonicalBlockHashes := [][]byte{} nextEpochCanonicalBlocks := []*Block{} var firstBlock *Block @@ -321,6 +322,9 @@ func (sync *synchronizer) syncEpoch(syncEpoch phase0.Epoch, client *Client, last if chainState.EpochOfSlot(slot) == syncEpoch { canonicalBlocks = append(canonicalBlocks, sync.cachedBlocks[slot]) canonicalBlockRoots = append(canonicalBlockRoots, sync.cachedBlocks[slot].Root[:]) + if blockIndex := sync.cachedBlocks[slot].GetBlockIndex(); blockIndex != nil { + canonicalBlockHashes = append(canonicalBlockHashes, blockIndex.ExecutionHash[:]) + } } else { nextEpochCanonicalBlocks = append(nextEpochCanonicalBlocks, sync.cachedBlocks[slot]) } @@ -388,7 +392,7 @@ func (sync *synchronizer) syncEpoch(syncEpoch phase0.Epoch, client *Client, last return fmt.Errorf("error persisting sync committee assignments to db: %v", err) } - if err := db.UpdateMevBlockByEpoch(uint64(syncEpoch), specs.SlotsPerEpoch, canonicalBlockRoots, tx); err != nil { + if err := db.UpdateMevBlockByEpoch(uint64(syncEpoch), specs.SlotsPerEpoch, canonicalBlockHashes, tx); err != nil { return fmt.Errorf("error while updating mev block proposal state: %v", err) } diff --git a/indexer/mevrelay/mevindexer.go b/indexer/mevrelay/mevindexer.go index 6f8753f..425d6d0 100644 --- a/indexer/mevrelay/mevindexer.go +++ b/indexer/mevrelay/mevindexer.go @@ -94,7 +94,7 @@ func (mev *MevIndexer) runUpdater() error { _, finalizedEpoch := mev.beaconIndexer.GetBlockCacheState() finalizedSlot := phase0.Slot(0) if finalizedEpoch > 0 { - finalizedSlot = mev.chainState.EpochToSlot(finalizedEpoch) - 1 + finalizedSlot = mev.chainState.EpochToSlot(finalizedEpoch) } loadedCount := uint64(0) for { @@ -168,25 +168,14 @@ func (mev *MevIndexer) runUpdater() error { finalizedEpoch, _ := mev.beaconIndexer.GetBlockCacheState() finalizedSlot := phase0.Slot(0) if finalizedEpoch > 0 { - finalizedSlot = mev.chainState.EpochToSlot(finalizedEpoch) - 1 + finalizedSlot = mev.chainState.EpochToSlot(finalizedEpoch) } - updatedMevBlocks = []*dbtypes.MevBlock{} for hash, cachedMevBlock := range mev.mevBlockCache { if cachedMevBlock.block.SlotNumber < uint64(finalizedSlot) { - proposed := mev.getMevBlockProposedStatus(cachedMevBlock.block, finalizedSlot) - if cachedMevBlock.block.Proposed != proposed { - cachedMevBlock.block.Proposed = proposed - updatedMevBlocks = append(updatedMevBlocks, cachedMevBlock.block) - } - delete(mev.mevBlockCache, hash) } } - err = mev.updateMevBlocks(updatedMevBlocks) - if err != nil { - return err - } mev.lastRefresh = time.Now() return nil @@ -382,19 +371,19 @@ func (mev *MevIndexer) loadMevBlocksFromRelay(relay *types.MevRelayConfig) error func (mev *MevIndexer) getMevBlockProposedStatus(mevBlock *dbtypes.MevBlock, finalizedSlot phase0.Slot) uint8 { proposed := uint8(0) - if mevBlock.SlotNumber > uint64(finalizedSlot) { + if mevBlock.SlotNumber >= uint64(finalizedSlot) { for _, block := range mev.beaconIndexer.GetBlocksByExecutionBlockHash(phase0.Hash32(mevBlock.BlockHash)) { - if proposed != 1 && mev.beaconIndexer.IsCanonicalBlock(block, nil) { + if mev.beaconIndexer.IsCanonicalBlock(block, nil) { proposed = 1 - } else { + } else if proposed != 1 { proposed = 2 } } } else { for _, block := range db.GetSlotsByBlockHash(mevBlock.BlockHash) { - if proposed != 1 && block.Status == dbtypes.Canonical { + if block.Status == dbtypes.Canonical { proposed = 1 - } else { + } else if proposed != 1 { proposed = 2 } }