Skip to content

Commit

Permalink
update mev block proposal status in synchronizer
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Jun 16, 2024
1 parent 075d253 commit 95e16ed
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
44 changes: 44 additions & 0 deletions db/mev_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

"github.com/ethpandaops/dora/dbtypes"
"github.com/ethpandaops/dora/utils"
"github.com/jmoiron/sqlx"
)

Expand Down Expand Up @@ -62,6 +63,49 @@ func InsertMevBlocks(mevBlocks []*dbtypes.MevBlock, tx *sqlx.Tx) error {
return nil
}

func UpdateMevBlockByEpoch(epoch uint64, canonicalHashes [][]byte, tx *sqlx.Tx) error {
var sql strings.Builder
var sqlArgs strings.Builder

args := []any{
epoch * utils.Config.Chain.Config.SlotsPerEpoch,
((epoch + 1) * utils.Config.Chain.Config.SlotsPerEpoch) - 1,
}

for i, hash := range canonicalHashes {
if sqlArgs.Len() > 0 {
fmt.Fprint(&sqlArgs, ",")
}
fmt.Fprintf(&sqlArgs, "$%v", (i + 3))
args = append(args, hash)
}

fmt.Fprint(&sql,
"UPDATE mev_blocks SET proposed = (",
"CASE ",
)
if len(canonicalHashes) > 0 {
fmt.Fprint(&sql,
"WHEN block_hash IN (",
sqlArgs.String(),
") THEN 1 ",
)
}
fmt.Fprint(&sql,
"WHEN proposed = 0 THEN 0 ",
"ELSE 2 ",
"END",
") ",
"WHERE slot_number >= $1 AND slot_number <= $2",
)

_, err := tx.Exec(sql.String(), args...)
if err != nil {
return err
}
return nil
}

func GetHighestMevBlockSlotByRelay(relayId uint8) (uint64, error) {
highestSlot := uint64(0)
err := ReaderDb.Get(&highestSlot, `
Expand Down
9 changes: 9 additions & 0 deletions indexer/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,17 @@ func (sync *synchronizerState) syncEpoch(syncEpoch uint64, retryCount int, lastT

// load blobs
lastSlot = firstSlot + utils.Config.Chain.Config.SlotsPerEpoch - 1
canonicalBlockHashes := [][]byte{}
blobs := []*BlobAssignment{}
for slot := firstSlot; slot <= lastSlot; slot++ {
block := sync.cachedBlocks[slot]
if block == nil {
continue
}

block.parseBlockRefs()
canonicalBlockHashes = append(canonicalBlockHashes, block.Refs.ExecutionHash)

blobKzgCommitments, _ := block.GetBlockBody().BlobKZGCommitments()
if len(blobKzgCommitments) == 0 {
continue
Expand Down Expand Up @@ -297,6 +301,11 @@ func (sync *synchronizerState) syncEpoch(syncEpoch uint64, retryCount int, lastT
}
}

err = db.UpdateMevBlockByEpoch(syncEpoch, canonicalBlockHashes, tx)
if err != nil {
return fmt.Errorf("error while updating mev block proposal state: %v", err)
}

err = db.SetExplorerState("indexer.syncstate", &dbtypes.IndexerSyncState{
Epoch: syncEpoch,
}, tx)
Expand Down
4 changes: 0 additions & 4 deletions services/mevindexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,6 @@ func (mev *MevIndexer) loadMevBlocksFromRelay(indexer *indexer.Indexer, relay *t
continue
}

if slot == 1884222 {
fmt.Printf("x\n")
}

if int64(slot) > highestSlot {
// skip for now, process in next refresh
continue
Expand Down

0 comments on commit 95e16ed

Please sign in to comment.