From 9f772947cc9d5db44264ba0e0658a86dc0ced00b Mon Sep 17 00:00:00 2001 From: invis-bitfly <162128378+invis-bitfly@users.noreply.github.com> Date: Mon, 13 Jan 2025 16:21:48 +0100 Subject: [PATCH] add(exporter): sanity check for el payload exporter --- .../modules/execution_payloads_exporter.go | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/backend/pkg/exporter/modules/execution_payloads_exporter.go b/backend/pkg/exporter/modules/execution_payloads_exporter.go index 7266821cc..7f8ebb0cd 100644 --- a/backend/pkg/exporter/modules/execution_payloads_exporter.go +++ b/backend/pkg/exporter/modules/execution_payloads_exporter.go @@ -1,6 +1,7 @@ package modules import ( + "bytes" "context" "database/sql" "fmt" @@ -154,9 +155,26 @@ func (d *executionPayloadsExporter) maintainTable() (err error) { if err != nil { return fmt.Errorf("error processing blocks: %w", err) } + // sanity checks: check if any block hashes are 0x0000000000000000000000000000000000000000000000000000000000000000 or duplicate, check if count matches expected + if uint64(len(resData)) != maxBlock-minBlock+1 { + return fmt.Errorf("error processing blocks: expected %v blocks, got %v", maxBlock-minBlock+1, len(resData)) + } + seen := make(map[string]bool) + emptyBlockHash := bytes.Repeat([]byte{0}, 32) + for _, r := range resData { + if len(r.BlockHash) == 0 { + return fmt.Errorf("error processing blocks: block hash is empty") + } + if bytes.Equal(r.BlockHash, emptyBlockHash) { + return fmt.Errorf("error processing blocks: block hash is all zeros") + } + if _, ok := seen[string(r.BlockHash)]; ok { + return fmt.Errorf("error processing blocks: duplicate block hash") + } + seen[string(r.BlockHash)] = true + } // update the execution_payloads table - log.Infof("preparing copy update to temp table") // load data into temp table