From 30880cd23b5e69ffb17ad9d4c56e3cbcd6a370ff Mon Sep 17 00:00:00 2001 From: Arnau Date: Tue, 23 Jul 2024 19:30:57 +0200 Subject: [PATCH 01/18] implementation completed, missing tests --- l1infotreesync/downloader.go | 228 ++++++++++ l1infotreesync/downloader_test.go | 398 ++++++++++++++++++ l1infotreesync/driver.go | 140 +++++++ l1infotreesync/driver_test.go | 211 ++++++++++ l1infotreesync/e2e_test.go | 71 ++++ l1infotreesync/l1infotreesync.go | 55 +++ l1infotreesync/mock_downloader_test.go | 100 +++++ l1infotreesync/mock_l2_test.go | 484 +++++++++++++++++++++ l1infotreesync/mock_processor_test.go | 81 ++++ l1infotreesync/mock_reorgdetector_test.go | 63 +++ l1infotreesync/processor.go | 487 ++++++++++++++++++++++ l1infotreesync/processor_test.go | 373 +++++++++++++++++ test/Makefile | 7 + 13 files changed, 2698 insertions(+) create mode 100644 l1infotreesync/downloader.go create mode 100644 l1infotreesync/downloader_test.go create mode 100644 l1infotreesync/driver.go create mode 100644 l1infotreesync/driver_test.go create mode 100644 l1infotreesync/e2e_test.go create mode 100644 l1infotreesync/l1infotreesync.go create mode 100644 l1infotreesync/mock_downloader_test.go create mode 100644 l1infotreesync/mock_l2_test.go create mode 100644 l1infotreesync/mock_processor_test.go create mode 100644 l1infotreesync/mock_reorgdetector_test.go create mode 100644 l1infotreesync/processor.go create mode 100644 l1infotreesync/processor_test.go diff --git a/l1infotreesync/downloader.go b/l1infotreesync/downloader.go new file mode 100644 index 00000000..a8ca4cc2 --- /dev/null +++ b/l1infotreesync/downloader.go @@ -0,0 +1,228 @@ +package l1infotreesync + +import ( + "context" + "math/big" + "time" + + "github.com/0xPolygon/cdk-contracts-tooling/contracts/elderberry/polygonzkevmglobalexitrootv2" + "github.com/0xPolygon/cdk/etherman" + "github.com/0xPolygon/cdk/log" + "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" +) + +const ( + waitForNewBlocksPeriod = time.Millisecond * 100 +) + +var ( + updateL1InfoTreeSignature = crypto.Keccak256Hash([]byte("UpdateL1InfoTree(bytes32,bytes32)")) +) + +type EthClienter interface { + ethereum.LogFilterer + ethereum.BlockNumberReader + ethereum.ChainReader + bind.ContractBackend +} + +type downloaderInterface interface { + waitForNewBlocks(ctx context.Context, lastBlockSeen uint64) (newLastBlock uint64) + getEventsByBlockRange(ctx context.Context, fromBlock, toBlock uint64) []block + getLogs(ctx context.Context, fromBlock, toBlock uint64) []types.Log + appendLog(b *block, l types.Log) + getBlockHeader(ctx context.Context, blockNum uint64) blockHeader +} + +type L1InfoTreeUpdate struct { + MainnetExitRoot common.Hash + RollupExitRoot common.Hash +} + +type block struct { + blockHeader + Events []L1InfoTreeUpdate +} + +type blockHeader struct { + Num uint64 + Hash common.Hash + ParentHash common.Hash + Timestamp uint64 +} + +type downloader struct { + syncBlockChunkSize uint64 + downloaderInterface +} + +func newDownloader( + GERAddr common.Address, + ethClient EthClienter, + syncBlockChunkSize uint64, + blockFinalityType etherman.BlockNumberFinality, +) (*downloader, error) { + GERContract, err := polygonzkevmglobalexitrootv2.NewPolygonzkevmglobalexitrootv2(GERAddr, ethClient) + if err != nil { + return nil, err + } + finality, err := blockFinalityType.ToBlockNum() + if err != nil { + return nil, err + } + return &downloader{ + syncBlockChunkSize: syncBlockChunkSize, + downloaderInterface: &downloaderImplementation{ + GERAddr: GERAddr, + GERContract: GERContract, + ethClient: ethClient, + blockFinality: finality, + }, + }, nil +} + +func (d *downloader) download(ctx context.Context, fromBlock uint64, downloadedCh chan block) { + lastBlock := d.waitForNewBlocks(ctx, 0) + for { + select { + case <-ctx.Done(): + log.Debug("closing channel") + close(downloadedCh) + return + default: + } + toBlock := fromBlock + d.syncBlockChunkSize + if toBlock > lastBlock { + toBlock = lastBlock + } + if fromBlock > toBlock { + log.Debug("waiting for new blocks, last block ", toBlock) + lastBlock = d.waitForNewBlocks(ctx, toBlock) + continue + } + log.Debugf("getting events from blocks %d to %d", fromBlock, toBlock) + blocks := d.getEventsByBlockRange(ctx, fromBlock, toBlock) + for _, b := range blocks { + log.Debugf("sending block %d to the driver (with events)", b.Num) + downloadedCh <- b + } + if len(blocks) == 0 || blocks[len(blocks)-1].Num < toBlock { + // Indicate the last downloaded block if there are not events on it + log.Debugf("sending block %d to the driver (without evvents)", toBlock) + downloadedCh <- block{ + blockHeader: d.getBlockHeader(ctx, toBlock), + } + } + fromBlock = toBlock + 1 + } +} + +type downloaderImplementation struct { + GERAddr common.Address + GERContract *polygonzkevmglobalexitrootv2.Polygonzkevmglobalexitrootv2 + ethClient EthClienter + blockFinality *big.Int +} + +func (d *downloaderImplementation) waitForNewBlocks(ctx context.Context, lastBlockSeen uint64) (newLastBlock uint64) { + attempts := 0 + for { + header, err := d.ethClient.HeaderByNumber(ctx, d.blockFinality) + if err != nil { + attempts++ + log.Error("error geting last block num from eth client: ", err) + retryHandler("waitForNewBlocks", attempts) + continue + } + if header.Number.Uint64() > lastBlockSeen { + return header.Number.Uint64() + } + time.Sleep(waitForNewBlocksPeriod) + } +} + +func (d *downloaderImplementation) getEventsByBlockRange(ctx context.Context, fromBlock, toBlock uint64) []block { + blocks := []block{} + logs := d.getLogs(ctx, fromBlock, toBlock) + for _, l := range logs { + if len(blocks) == 0 || blocks[len(blocks)-1].Num < l.BlockNumber { + b := d.getBlockHeader(ctx, l.BlockNumber) + blocks = append(blocks, block{ + blockHeader: blockHeader{ + Num: l.BlockNumber, + Hash: l.BlockHash, + Timestamp: b.Timestamp, + ParentHash: b.ParentHash, + }, + Events: []L1InfoTreeUpdate{}, + }) + } + d.appendLog(&blocks[len(blocks)-1], l) + } + + return blocks +} + +func (d *downloaderImplementation) getLogs(ctx context.Context, fromBlock, toBlock uint64) []types.Log { + query := ethereum.FilterQuery{ + FromBlock: new(big.Int).SetUint64(fromBlock), + Addresses: []common.Address{d.GERAddr}, + Topics: [][]common.Hash{ + {updateL1InfoTreeSignature}, + }, + ToBlock: new(big.Int).SetUint64(toBlock), + } + attempts := 0 + for { + logs, err := d.ethClient.FilterLogs(ctx, query) + if err != nil { + attempts++ + log.Error("error calling FilterLogs to eth client: ", err) + retryHandler("getLogs", attempts) + continue + } + return logs + } +} + +func (d *downloaderImplementation) appendLog(b *block, l types.Log) { + switch l.Topics[0] { + case updateL1InfoTreeSignature: + l1InfoTreeUpdate, err := d.GERContract.ParseUpdateL1InfoTree(l) + if err != nil { + log.Fatalf( + "error parsing log %+v using d.GERContract.ParseUpdateL1InfoTree: %v", + l, err, + ) + } + b.Events = append(b.Events, L1InfoTreeUpdate{ + MainnetExitRoot: l1InfoTreeUpdate.MainnetExitRoot, + RollupExitRoot: l1InfoTreeUpdate.MainnetExitRoot, + }) + default: + log.Fatalf("unexpected log %+v", l) + } +} + +func (d *downloaderImplementation) getBlockHeader(ctx context.Context, blockNum uint64) blockHeader { + attempts := 0 + for { + header, err := d.ethClient.HeaderByNumber(ctx, big.NewInt(int64(blockNum))) + if err != nil { + attempts++ + log.Errorf("error getting block header for block %d, err: %v", blockNum, err) + retryHandler("getBlockHeader", attempts) + continue + } + return blockHeader{ + Num: header.Number.Uint64(), + Hash: header.Hash(), + ParentHash: header.ParentHash, + Timestamp: header.Time, + } + } +} diff --git a/l1infotreesync/downloader_test.go b/l1infotreesync/downloader_test.go new file mode 100644 index 00000000..28daf69b --- /dev/null +++ b/l1infotreesync/downloader_test.go @@ -0,0 +1,398 @@ +package l1infotreesync + +import ( + "context" + "errors" + "math/big" + "testing" + "time" + + "github.com/0xPolygon/cdk/etherman" + "github.com/0xPolygon/cdk/log" + "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" +) + +var ( + contractAddr = common.HexToAddress("1234567890") +) + +const ( + syncBlockChunck = uint64(10) +) + +func TestGetEventsByBlockRange(t *testing.T) { + type testCase struct { + description string + inputLogs []types.Log + fromBlock, toBlock uint64 + expectedBlocks []block + } + testCases := []testCase{} + clientMock := NewL2Mock(t) + ctx := context.Background() + d, err := newDownloader(contractAddr, clientMock, syncBlockChunck, etherman.LatestBlock) + require.NoError(t, err) + + // case 0: single block, no events + case0 := testCase{ + description: "case 0: single block, no events", + inputLogs: []types.Log{}, + fromBlock: 1, + toBlock: 3, + expectedBlocks: []block{}, + } + testCases = append(testCases, case0) + + // case 1: single block, single event + logC1, updateC1 := generateUpdateL1InfoTree(t, 3) + logsC1 := []types.Log{ + *logC1, + } + blocksC1 := []block{ + { + blockHeader: blockHeader{ + Num: logC1.BlockNumber, + Hash: logC1.BlockHash, + ParentHash: common.HexToHash("foo"), + }, + Events: []L1InfoTreeUpdate{ + updateC1, + }, + }, + } + case1 := testCase{ + description: "case 1: single block, single event", + inputLogs: logsC1, + fromBlock: 3, + toBlock: 3, + expectedBlocks: blocksC1, + } + testCases = append(testCases, case1) + + // case 2: single block, multiple events + logC2_1, updateC2_1 := generateUpdateL1InfoTree(t, 5) + logC2_2, updateC2_2 := generateUpdateL1InfoTree(t, 5) + logC2_3, updateC2_3 := generateUpdateL1InfoTree(t, 5) + logC2_4, updateC2_4 := generateUpdateL1InfoTree(t, 5) + logsC2 := []types.Log{ + *logC2_1, + *logC2_2, + *logC2_3, + *logC2_4, + } + blocksC2 := []block{ + { + blockHeader: blockHeader{ + Num: logC2_1.BlockNumber, + Hash: logC2_1.BlockHash, + ParentHash: common.HexToHash("foo"), + }, + Events: []L1InfoTreeUpdate{ + updateC2_1, + updateC2_2, + updateC2_3, + updateC2_4, + }, + }, + } + case2 := testCase{ + description: "case 2: single block, multiple events", + inputLogs: logsC2, + fromBlock: 5, + toBlock: 5, + expectedBlocks: blocksC2, + } + testCases = append(testCases, case2) + + // case 3: multiple blocks, some events + logC3_1, updateC3_1 := generateUpdateL1InfoTree(t, 7) + logC3_2, updateC3_2 := generateUpdateL1InfoTree(t, 7) + logC3_3, updateC3_3 := generateUpdateL1InfoTree(t, 8) + logC3_4, updateC3_4 := generateUpdateL1InfoTree(t, 8) + logsC3 := []types.Log{ + *logC3_1, + *logC3_2, + *logC3_3, + *logC3_4, + } + blocksC3 := []block{ + { + blockHeader: blockHeader{ + Num: logC3_1.BlockNumber, + Hash: logC3_1.BlockHash, + ParentHash: common.HexToHash("foo"), + }, + Events: []L1InfoTreeUpdate{ + updateC3_1, + updateC3_2, + }, + }, + { + blockHeader: blockHeader{ + Num: logC3_3.BlockNumber, + Hash: logC3_3.BlockHash, + ParentHash: common.HexToHash("foo"), + }, + Events: []L1InfoTreeUpdate{ + updateC3_3, + updateC3_4, + }, + }, + } + case3 := testCase{ + description: "case 3: multiple blocks, some events", + inputLogs: logsC3, + fromBlock: 7, + toBlock: 8, + expectedBlocks: blocksC3, + } + testCases = append(testCases, case3) + + for _, tc := range testCases { + query := ethereum.FilterQuery{ + FromBlock: new(big.Int).SetUint64(tc.fromBlock), + Addresses: []common.Address{contractAddr}, + Topics: [][]common.Hash{ + {updateL1InfoTreeSignature}, + }, + ToBlock: new(big.Int).SetUint64(tc.toBlock), + } + clientMock. + On("FilterLogs", mock.Anything, query). + Return(tc.inputLogs, nil) + for _, b := range tc.expectedBlocks { + clientMock. + On("HeaderByNumber", mock.Anything, big.NewInt(int64(b.Num))). + Return(&types.Header{ + Number: big.NewInt(int64(b.Num)), + ParentHash: common.HexToHash("foo"), + }, nil) + } + + actualBlocks := d.getEventsByBlockRange(ctx, tc.fromBlock, tc.toBlock) + require.Equal(t, tc.expectedBlocks, actualBlocks, tc.description) + } +} + +func generateUpdateL1InfoTree(t *testing.T, blockNum uint32) (*types.Log, L1InfoTreeUpdate) { + b := L1InfoTreeUpdate{ + MainnetExitRoot: common.BigToHash(big.NewInt(int64(blockNum))), + RollupExitRoot: common.BigToHash(big.NewInt(int64(blockNum))), + } + var rollup, mainnet [32]byte + mainnet = b.MainnetExitRoot + rollup = b.RollupExitRoot + log := &types.Log{ + Address: contractAddr, + BlockNumber: uint64(blockNum), + BlockHash: common.BytesToHash(uint64ToBytes(uint64(blockNum))), + Topics: []common.Hash{ + updateL1InfoTreeSignature, + mainnet, + rollup, + }, + Data: nil, + } + return log, b +} + +func TestDownload(t *testing.T) { + /* + NOTE: due to the concurrent nature of this test (the function being tested runs through a goroutine) + if the mock doesn't match, the goroutine will get stuck and the test will timeout + */ + d := NewDownloaderMock(t) + downloadCh := make(chan block, 1) + ctx := context.Background() + ctx1, cancel := context.WithCancel(ctx) + expectedBlocks := []block{} + clientMock := NewL2Mock(t) + dwnldr, err := newDownloader(contractAddr, clientMock, syncBlockChunck, etherman.LatestBlock) + require.NoError(t, err) + dwnldr.downloaderInterface = d + + d.On("waitForNewBlocks", mock.Anything, uint64(0)). + Return(uint64(1)) + // iteratiion 0: + // last block is 1, download that block (no events and wait) + b1 := block{ + blockHeader: blockHeader{ + Num: 1, + Hash: common.HexToHash("01"), + }, + } + expectedBlocks = append(expectedBlocks, b1) + d.On("getEventsByBlockRange", mock.Anything, uint64(0), uint64(1)). + Return([]block{}) + d.On("getBlockHeader", mock.Anything, uint64(1)). + Return(b1.blockHeader) + + // iteration 1: wait for next block to be created + d.On("waitForNewBlocks", mock.Anything, uint64(1)). + After(time.Millisecond * 100). + Return(uint64(2)).Once() + + // iteration 2: block 2 has events + b2 := block{ + blockHeader: blockHeader{ + Num: 2, + Hash: common.HexToHash("02"), + }, + } + expectedBlocks = append(expectedBlocks, b2) + d.On("getEventsByBlockRange", mock.Anything, uint64(2), uint64(2)). + Return([]block{b2}) + + // iteration 3: wait for next block to be created (jump to block 8) + d.On("waitForNewBlocks", mock.Anything, uint64(2)). + After(time.Millisecond * 100). + Return(uint64(8)).Once() + + // iteration 4: blocks 6 and 7 have events + b6 := block{ + blockHeader: blockHeader{ + Num: 6, + Hash: common.HexToHash("06"), + }, + Events: []L1InfoTreeUpdate{ + {RollupExitRoot: common.HexToHash("06")}, + }, + } + b7 := block{ + blockHeader: blockHeader{ + Num: 7, + Hash: common.HexToHash("07"), + }, + Events: []L1InfoTreeUpdate{ + {MainnetExitRoot: common.HexToHash("07")}, + }, + } + b8 := block{ + blockHeader: blockHeader{ + Num: 8, + Hash: common.HexToHash("08"), + }, + } + expectedBlocks = append(expectedBlocks, b6, b7, b8) + d.On("getEventsByBlockRange", mock.Anything, uint64(3), uint64(8)). + Return([]block{b6, b7}) + d.On("getBlockHeader", mock.Anything, uint64(8)). + Return(b8.blockHeader) + + // iteration 5: wait for next block to be created (jump to block 30) + d.On("waitForNewBlocks", mock.Anything, uint64(8)). + After(time.Millisecond * 100). + Return(uint64(30)).Once() + + // iteration 6: from block 9 to 19, no events + b19 := block{ + blockHeader: blockHeader{ + Num: 19, + Hash: common.HexToHash("19"), + }, + } + expectedBlocks = append(expectedBlocks, b19) + d.On("getEventsByBlockRange", mock.Anything, uint64(9), uint64(19)). + Return([]block{}) + d.On("getBlockHeader", mock.Anything, uint64(19)). + Return(b19.blockHeader) + + // iteration 7: from block 20 to 30, events on last block + b30 := block{ + blockHeader: blockHeader{ + Num: 30, + Hash: common.HexToHash("30"), + }, + Events: []L1InfoTreeUpdate{ + {RollupExitRoot: common.HexToHash("30")}, + }, + } + expectedBlocks = append(expectedBlocks, b30) + d.On("getEventsByBlockRange", mock.Anything, uint64(20), uint64(30)). + Return([]block{b30}) + + // iteration 8: wait for next block to be created (jump to block 35) + d.On("waitForNewBlocks", mock.Anything, uint64(30)). + After(time.Millisecond * 100). + Return(uint64(35)).Once() + + go dwnldr.download(ctx1, 0, downloadCh) + for _, expectedBlock := range expectedBlocks { + actualBlock := <-downloadCh + log.Debugf("block %d received!", actualBlock.Num) + require.Equal(t, expectedBlock, actualBlock) + } + log.Debug("canceling") + cancel() + _, ok := <-downloadCh + require.False(t, ok) +} + +func TestWaitForNewBlocks(t *testing.T) { + retryAfterErrorPeriod = time.Millisecond * 100 + clientMock := NewL2Mock(t) + ctx := context.Background() + d, err := newDownloader(contractAddr, clientMock, syncBlockChunck, etherman.LatestBlock) + require.NoError(t, err) + + // at first attempt + currentBlock := uint64(5) + expectedBlock := uint64(6) + clientMock.On("HeaderByNumber", ctx, mock.Anything).Return(&types.Header{ + Number: big.NewInt(6), + }, nil).Once() + actualBlock := d.waitForNewBlocks(ctx, currentBlock) + assert.Equal(t, expectedBlock, actualBlock) + + // 2 iterations + clientMock.On("HeaderByNumber", ctx, mock.Anything).Return(&types.Header{ + Number: big.NewInt(5), + }, nil).Once() + clientMock.On("HeaderByNumber", ctx, mock.Anything).Return(&types.Header{ + Number: big.NewInt(6), + }, nil).Once() + actualBlock = d.waitForNewBlocks(ctx, currentBlock) + assert.Equal(t, expectedBlock, actualBlock) + + // after error from client + clientMock.On("HeaderByNumber", ctx, mock.Anything).Return(nil, errors.New("foo")).Once() + clientMock.On("HeaderByNumber", ctx, mock.Anything).Return(&types.Header{ + Number: big.NewInt(6), + }, nil).Once() + actualBlock = d.waitForNewBlocks(ctx, currentBlock) + assert.Equal(t, expectedBlock, actualBlock) +} + +func TestGetBlockHeader(t *testing.T) { + retryAfterErrorPeriod = time.Millisecond * 100 + clientMock := NewL2Mock(t) + ctx := context.Background() + d, err := newDownloader(contractAddr, clientMock, syncBlockChunck, etherman.LatestBlock) + require.NoError(t, err) + + blockNum := uint64(5) + blockNumBig := big.NewInt(5) + returnedBlock := &types.Header{ + Number: blockNumBig, + } + expectedBlock := blockHeader{ + Num: 5, + Hash: returnedBlock.Hash(), + } + + // at first attempt + clientMock.On("HeaderByNumber", ctx, blockNumBig).Return(returnedBlock, nil).Once() + actualBlock := d.getBlockHeader(ctx, blockNum) + assert.Equal(t, expectedBlock, actualBlock) + + // after error from client + clientMock.On("HeaderByNumber", ctx, blockNumBig).Return(nil, errors.New("foo")).Once() + clientMock.On("HeaderByNumber", ctx, blockNumBig).Return(returnedBlock, nil).Once() + actualBlock = d.getBlockHeader(ctx, blockNum) + assert.Equal(t, expectedBlock, actualBlock) +} diff --git a/l1infotreesync/driver.go b/l1infotreesync/driver.go new file mode 100644 index 00000000..9952f797 --- /dev/null +++ b/l1infotreesync/driver.go @@ -0,0 +1,140 @@ +package l1infotreesync + +import ( + "context" + + "github.com/0xPolygon/cdk/log" + "github.com/0xPolygon/cdk/reorgdetector" + "github.com/ethereum/go-ethereum/common" +) + +const ( + downloadBufferSize = 1000 + reorgDetectorID = "localbridgesync" +) + +type downloaderFull interface { + downloaderInterface + download(ctx context.Context, fromBlock uint64, downloadedCh chan block) +} + +type driver struct { + reorgDetector ReorgDetector + reorgSub *reorgdetector.Subscription + processor processorInterface + downloader downloaderFull +} + +type processorInterface interface { + getLastProcessedBlock(ctx context.Context) (uint64, error) + processBlock(block block) error + reorg(firstReorgedBlock uint64) error +} + +type ReorgDetector interface { + Subscribe(id string) *reorgdetector.Subscription + AddBlockToTrack(ctx context.Context, id string, blockNum uint64, blockHash common.Hash) error +} + +func newDriver( + reorgDetector ReorgDetector, + processor processorInterface, + downloader downloaderFull, +) (*driver, error) { + reorgSub := reorgDetector.Subscribe(reorgDetectorID) + return &driver{ + reorgDetector: reorgDetector, + reorgSub: reorgSub, + processor: processor, + downloader: downloader, + }, nil +} + +func (d *driver) Sync(ctx context.Context) { +reset: + var ( + lastProcessedBlock uint64 + attempts int + err error + ) + for { + lastProcessedBlock, err = d.processor.getLastProcessedBlock(ctx) + if err != nil { + attempts++ + log.Error("error geting last processed block: ", err) + retryHandler("Sync", attempts) + continue + } + break + } + cancellableCtx, cancel := context.WithCancel(ctx) + defer cancel() + + // start downloading + downloadCh := make(chan block, downloadBufferSize) + go d.downloader.download(cancellableCtx, lastProcessedBlock, downloadCh) + + for { + select { + case b := <-downloadCh: + log.Debug("handleNewBlock") + d.handleNewBlock(ctx, b) + case firstReorgedBlock := <-d.reorgSub.FirstReorgedBlock: + log.Debug("handleReorg") + d.handleReorg(cancel, downloadCh, firstReorgedBlock) + goto reset + } + } +} + +func (d *driver) handleNewBlock(ctx context.Context, b block) { + attempts := 0 + for { + err := d.reorgDetector.AddBlockToTrack(ctx, reorgDetectorID, b.Num, b.Hash) + if err != nil { + attempts++ + log.Errorf("error adding block %d to tracker: %v", b.Num, err) + retryHandler("handleNewBlock", attempts) + continue + } + break + } + attempts = 0 + for { + err := d.processor.processBlock(b) + if err != nil { + attempts++ + log.Errorf("error processing events for blcok %d, err: ", b.Num, err) + retryHandler("handleNewBlock", attempts) + continue + } + break + } +} + +func (d *driver) handleReorg( + cancel context.CancelFunc, downloadCh chan block, firstReorgedBlock uint64, +) { + // stop downloader + cancel() + _, ok := <-downloadCh + for ok { + _, ok = <-downloadCh + } + // handle reorg + attempts := 0 + for { + err := d.processor.reorg(firstReorgedBlock) + if err != nil { + attempts++ + log.Errorf( + "error processing reorg, last valid block %d, err: %v", + firstReorgedBlock, err, + ) + retryHandler("handleReorg", attempts) + continue + } + break + } + d.reorgSub.ReorgProcessed <- true +} diff --git a/l1infotreesync/driver_test.go b/l1infotreesync/driver_test.go new file mode 100644 index 00000000..e206973a --- /dev/null +++ b/l1infotreesync/driver_test.go @@ -0,0 +1,211 @@ +package l1infotreesync + +import ( + "context" + "errors" + "sync" + "testing" + "time" + + "github.com/0xPolygon/cdk/log" + "github.com/0xPolygon/cdk/reorgdetector" + "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" +) + +func TestSync(t *testing.T) { + retryAfterErrorPeriod = time.Millisecond * 100 + rdm := NewReorgDetectorMock(t) + pm := NewProcessorMock(t) + dm := NewDownloaderMock(t) + firstReorgedBlock := make(chan uint64) + reorgProcessed := make(chan bool) + rdm.On("Subscribe", reorgDetectorID).Return(&reorgdetector.Subscription{ + FirstReorgedBlock: firstReorgedBlock, + ReorgProcessed: reorgProcessed, + }) + driver, err := newDriver(rdm, pm, dm) + require.NoError(t, err) + ctx := context.Background() + expectedBlock1 := block{ + blockHeader: blockHeader{ + Num: 3, + Hash: common.HexToHash("03"), + }, + } + expectedBlock2 := block{ + blockHeader: blockHeader{ + Num: 9, + Hash: common.HexToHash("09"), + }, + } + type reorgSemaphore struct { + mu sync.Mutex + green bool + } + reorg1Completed := reorgSemaphore{} + dm.On("download", mock.Anything, mock.Anything, mock.Anything).Run(func(args mock.Arguments) { + ctx := args.Get(0).(context.Context) + downloadedCh := args.Get(2).(chan block) + log.Info("entering mock loop") + for { + select { + case <-ctx.Done(): + log.Info("closing channel") + close(downloadedCh) + return + default: + } + reorg1Completed.mu.Lock() + green := reorg1Completed.green + reorg1Completed.mu.Unlock() + if green { + downloadedCh <- expectedBlock2 + } else { + downloadedCh <- expectedBlock1 + } + time.Sleep(100 * time.Millisecond) + } + }) + + // Mocking this actions, the driver should "store" all the blocks from the downloader + pm.On("getLastProcessedBlock", ctx). + Return(uint64(3), nil) + rdm.On("AddBlockToTrack", ctx, reorgDetectorID, expectedBlock1.Num, expectedBlock1.Hash). + Return(nil) + pm.On("storeBridgeEvents", expectedBlock1.Num, expectedBlock1.Events). + Return(nil) + rdm.On("AddBlockToTrack", ctx, reorgDetectorID, expectedBlock2.Num, expectedBlock2.Hash). + Return(nil) + pm.On("storeBridgeEvents", expectedBlock2.Num, expectedBlock2.Events). + Return(nil) + go driver.Sync(ctx) + time.Sleep(time.Millisecond * 200) // time to download expectedBlock1 + + // Trigger reorg 1 + reorgedBlock1 := uint64(5) + pm.On("reorg", reorgedBlock1).Return(nil) + firstReorgedBlock <- reorgedBlock1 + ok := <-reorgProcessed + require.True(t, ok) + reorg1Completed.mu.Lock() + reorg1Completed.green = true + reorg1Completed.mu.Unlock() + time.Sleep(time.Millisecond * 200) // time to download expectedBlock2 + + // Trigger reorg 2: syncer restarts the porcess + reorgedBlock2 := uint64(7) + pm.On("reorg", reorgedBlock2).Return(nil) + firstReorgedBlock <- reorgedBlock2 + ok = <-reorgProcessed + require.True(t, ok) +} + +func TestHandleNewBlock(t *testing.T) { + retryAfterErrorPeriod = time.Millisecond * 100 + rdm := NewReorgDetectorMock(t) + pm := NewProcessorMock(t) + dm := NewDownloaderMock(t) + rdm.On("Subscribe", reorgDetectorID).Return(&reorgdetector.Subscription{}) + driver, err := newDriver(rdm, pm, dm) + require.NoError(t, err) + ctx := context.Background() + + // happy path + b1 := block{ + blockHeader: blockHeader{ + Num: 1, + Hash: common.HexToHash("f00"), + }, + } + rdm. + On("AddBlockToTrack", ctx, reorgDetectorID, b1.Num, b1.Hash). + Return(nil) + pm.On("storeBridgeEvents", b1.Num, b1.Events). + Return(nil) + driver.handleNewBlock(ctx, b1) + + // reorg deteector fails once + b2 := block{ + blockHeader: blockHeader{ + Num: 2, + Hash: common.HexToHash("f00"), + }, + } + rdm. + On("AddBlockToTrack", ctx, reorgDetectorID, b2.Num, b2.Hash). + Return(errors.New("foo")).Once() + rdm. + On("AddBlockToTrack", ctx, reorgDetectorID, b2.Num, b2.Hash). + Return(nil).Once() + pm.On("storeBridgeEvents", b2.Num, b2.Events). + Return(nil) + driver.handleNewBlock(ctx, b2) + + // processor fails once + b3 := block{ + blockHeader: blockHeader{ + Num: 3, + Hash: common.HexToHash("f00"), + }, + } + rdm. + On("AddBlockToTrack", ctx, reorgDetectorID, b3.Num, b3.Hash). + Return(nil) + pm.On("storeBridgeEvents", b3.Num, b3.Events). + Return(errors.New("foo")).Once() + pm.On("storeBridgeEvents", b3.Num, b3.Events). + Return(nil).Once() + driver.handleNewBlock(ctx, b3) + +} + +func TestHandleReorg(t *testing.T) { + retryAfterErrorPeriod = time.Millisecond * 100 + rdm := NewReorgDetectorMock(t) + pm := NewProcessorMock(t) + dm := NewDownloaderMock(t) + reorgProcessed := make(chan bool) + rdm.On("Subscribe", reorgDetectorID).Return(&reorgdetector.Subscription{ + ReorgProcessed: reorgProcessed, + }) + driver, err := newDriver(rdm, pm, dm) + require.NoError(t, err) + ctx := context.Background() + + // happy path + _, cancel := context.WithCancel(ctx) + downloadCh := make(chan block) + firstReorgedBlock := uint64(5) + pm.On("reorg", firstReorgedBlock).Return(nil) + go driver.handleReorg(cancel, downloadCh, firstReorgedBlock) + close(downloadCh) + done := <-reorgProcessed + require.True(t, done) + + // download ch sends some garbage + _, cancel = context.WithCancel(ctx) + downloadCh = make(chan block) + firstReorgedBlock = uint64(6) + pm.On("reorg", firstReorgedBlock).Return(nil) + go driver.handleReorg(cancel, downloadCh, firstReorgedBlock) + downloadCh <- block{} + downloadCh <- block{} + downloadCh <- block{} + close(downloadCh) + done = <-reorgProcessed + require.True(t, done) + + // processor fails 2 times + _, cancel = context.WithCancel(ctx) + downloadCh = make(chan block) + firstReorgedBlock = uint64(7) + pm.On("reorg", firstReorgedBlock).Return(errors.New("foo")).Once() + pm.On("reorg", firstReorgedBlock).Return(errors.New("foo")).Once() + pm.On("reorg", firstReorgedBlock).Return(nil).Once() + go driver.handleReorg(cancel, downloadCh, firstReorgedBlock) + close(downloadCh) + done = <-reorgProcessed + require.True(t, done) +} diff --git a/l1infotreesync/e2e_test.go b/l1infotreesync/e2e_test.go new file mode 100644 index 00000000..5e97e92a --- /dev/null +++ b/l1infotreesync/e2e_test.go @@ -0,0 +1,71 @@ +package l1infotreesync + +import ( + "context" + "math/big" + "strconv" + "testing" + "time" + + "github.com/0xPolygon/cdk-contracts-tooling/contracts/elderberry/polygonzkevmglobalexitrootv2" + "github.com/0xPolygon/cdk/etherman" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethclient/simulated" + "github.com/stretchr/testify/require" +) + +func newSimulatedClient(auth *bind.TransactOpts) ( + client *simulated.Backend, + gerAddr common.Address, + gerContract *polygonzkevmglobalexitrootv2.Polygonzkevmglobalexitrootv2, + err error, +) { + balance, _ := new(big.Int).SetString("10000000000000000000000000", 10) //nolint:gomnd + address := auth.From + genesisAlloc := map[common.Address]types.Account{ + address: { + Balance: balance, + }, + } + blockGasLimit := uint64(999999999999999999) //nolint:gomnd + client = simulated.NewBackend(genesisAlloc, simulated.WithBlockGasLimit(blockGasLimit)) + + gerAddr, _, gerContract, err = polygonzkevmglobalexitrootv2.DeployPolygonzkevmglobalexitrootv2(auth, client.Client(), auth.From, auth.From) + + client.Commit() + return +} + +func TestE2E(t *testing.T) { + ctx := context.Background() + dbPath := t.TempDir() + privateKey, err := crypto.GenerateKey() + require.NoError(t, err) + auth, err := bind.NewKeyedTransactorWithChainID(privateKey, big.NewInt(1337)) + require.NoError(t, err) + rdm := NewReorgDetectorMock(t) + client, gerAddr, gerSc, err := newSimulatedClient(auth) + syncer, err := New(ctx, dbPath, gerAddr, 10, etherman.LatestBlock, rdm, client.Client(), 32) + require.NoError(t, err) + go syncer.Sync(ctx) + + // Update GER 10 times + for i := 0; i < 10; i++ { + gerSc.UpdateExitRoot(auth, common.HexToHash(strconv.Itoa(i))) + client.Commit() + // Let the processor catch up + time.Sleep(time.Millisecond * 100) + + expectedRoot, err := gerSc.GetRoot(nil) + require.NoError(t, err) + info, err := syncer.GetInfoByRoot(ctx, expectedRoot) + require.NoError(t, err) + require.Equal(t, expectedRoot, info.L1InfoTreeRoot) + info2, err := syncer.GetInfoByIndex(ctx, uint32(i)) + require.NoError(t, err) + require.Equal(t, info, info2) + } +} diff --git a/l1infotreesync/l1infotreesync.go b/l1infotreesync/l1infotreesync.go new file mode 100644 index 00000000..8a5ffde1 --- /dev/null +++ b/l1infotreesync/l1infotreesync.go @@ -0,0 +1,55 @@ +package l1infotreesync + +import ( + "context" + "time" + + "github.com/0xPolygon/cdk/etherman" + "github.com/0xPolygon/cdk/log" + "github.com/ethereum/go-ethereum/common" +) + +var ( + retryAfterErrorPeriod = time.Second * 10 + maxRetryAttemptsAfterError = 5 +) + +type L1InfoTreeSync struct { + *processor + *driver +} + +func New( + ctx context.Context, + dbPath string, + globalExitRoot common.Address, + syncBlockChunkSize uint64, + blockFinalityType etherman.BlockNumberFinality, + rd ReorgDetector, + l2Client EthClienter, + treeHeight uint8, +) (*L1InfoTreeSync, error) { + p, err := newProcessor(ctx, dbPath, treeHeight) + if err != nil { + return nil, err + } + dwn, err := newDownloader(globalExitRoot, l2Client, syncBlockChunkSize, blockFinalityType) + if err != nil { + return nil, err + } + dri, err := newDriver(rd, p, dwn) + if err != nil { + return nil, err + } + return &L1InfoTreeSync{p, dri}, nil +} + +func retryHandler(funcName string, attempts int) { + if attempts >= maxRetryAttemptsAfterError { + log.Fatalf( + "%s failed too many times (%d)", + funcName, maxRetryAttemptsAfterError, + ) + } + time.Sleep(retryAfterErrorPeriod) +} diff --git a/l1infotreesync/mock_downloader_test.go b/l1infotreesync/mock_downloader_test.go new file mode 100644 index 00000000..fca72678 --- /dev/null +++ b/l1infotreesync/mock_downloader_test.go @@ -0,0 +1,100 @@ +// Code generated by mockery v2.22.1. DO NOT EDIT. + +package l1infotreesync + +import ( + context "context" + + types "github.com/ethereum/go-ethereum/core/types" + mock "github.com/stretchr/testify/mock" +) + +// DownloaderMock is an autogenerated mock type for the downloaderFull type +type DownloaderMock struct { + mock.Mock +} + +// appendLog provides a mock function with given fields: b, l +func (_m *DownloaderMock) appendLog(b *block, l types.Log) { + _m.Called(b, l) +} + +// download provides a mock function with given fields: ctx, fromBlock, downloadedCh +func (_m *DownloaderMock) download(ctx context.Context, fromBlock uint64, downloadedCh chan block) { + _m.Called(ctx, fromBlock, downloadedCh) +} + +// getBlockHeader provides a mock function with given fields: ctx, blockNum +func (_m *DownloaderMock) getBlockHeader(ctx context.Context, blockNum uint64) blockHeader { + ret := _m.Called(ctx, blockNum) + + var r0 blockHeader + if rf, ok := ret.Get(0).(func(context.Context, uint64) blockHeader); ok { + r0 = rf(ctx, blockNum) + } else { + r0 = ret.Get(0).(blockHeader) + } + + return r0 +} + +// getEventsByBlockRange provides a mock function with given fields: ctx, fromBlock, toBlock +func (_m *DownloaderMock) getEventsByBlockRange(ctx context.Context, fromBlock uint64, toBlock uint64) []block { + ret := _m.Called(ctx, fromBlock, toBlock) + + var r0 []block + if rf, ok := ret.Get(0).(func(context.Context, uint64, uint64) []block); ok { + r0 = rf(ctx, fromBlock, toBlock) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]block) + } + } + + return r0 +} + +// getLogs provides a mock function with given fields: ctx, fromBlock, toBlock +func (_m *DownloaderMock) getLogs(ctx context.Context, fromBlock uint64, toBlock uint64) []types.Log { + ret := _m.Called(ctx, fromBlock, toBlock) + + var r0 []types.Log + if rf, ok := ret.Get(0).(func(context.Context, uint64, uint64) []types.Log); ok { + r0 = rf(ctx, fromBlock, toBlock) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Log) + } + } + + return r0 +} + +// waitForNewBlocks provides a mock function with given fields: ctx, lastBlockSeen +func (_m *DownloaderMock) waitForNewBlocks(ctx context.Context, lastBlockSeen uint64) uint64 { + ret := _m.Called(ctx, lastBlockSeen) + + var r0 uint64 + if rf, ok := ret.Get(0).(func(context.Context, uint64) uint64); ok { + r0 = rf(ctx, lastBlockSeen) + } else { + r0 = ret.Get(0).(uint64) + } + + return r0 +} + +type mockConstructorTestingTNewDownloaderMock interface { + mock.TestingT + Cleanup(func()) +} + +// NewDownloaderMock creates a new instance of DownloaderMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewDownloaderMock(t mockConstructorTestingTNewDownloaderMock) *DownloaderMock { + mock := &DownloaderMock{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/l1infotreesync/mock_l2_test.go b/l1infotreesync/mock_l2_test.go new file mode 100644 index 00000000..9ab6868d --- /dev/null +++ b/l1infotreesync/mock_l2_test.go @@ -0,0 +1,484 @@ +// Code generated by mockery v2.22.1. DO NOT EDIT. + +package l1infotreesync + +import ( + context "context" + big "math/big" + + common "github.com/ethereum/go-ethereum/common" + + ethereum "github.com/ethereum/go-ethereum" + + mock "github.com/stretchr/testify/mock" + + types "github.com/ethereum/go-ethereum/core/types" +) + +// L2Mock is an autogenerated mock type for the EthClienter type +type L2Mock struct { + mock.Mock +} + +// BlockByHash provides a mock function with given fields: ctx, hash +func (_m *L2Mock) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) { + ret := _m.Called(ctx, hash) + + var r0 *types.Block + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, common.Hash) (*types.Block, error)); ok { + return rf(ctx, hash) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Hash) *types.Block); ok { + r0 = rf(ctx, hash) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Block) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Hash) error); ok { + r1 = rf(ctx, hash) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// BlockByNumber provides a mock function with given fields: ctx, number +func (_m *L2Mock) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) { + ret := _m.Called(ctx, number) + + var r0 *types.Block + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *big.Int) (*types.Block, error)); ok { + return rf(ctx, number) + } + if rf, ok := ret.Get(0).(func(context.Context, *big.Int) *types.Block); ok { + r0 = rf(ctx, number) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Block) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *big.Int) error); ok { + r1 = rf(ctx, number) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// BlockNumber provides a mock function with given fields: ctx +func (_m *L2Mock) BlockNumber(ctx context.Context) (uint64, error) { + ret := _m.Called(ctx) + + var r0 uint64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (uint64, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) uint64); ok { + r0 = rf(ctx) + } else { + r0 = ret.Get(0).(uint64) + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CallContract provides a mock function with given fields: ctx, call, blockNumber +func (_m *L2Mock) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) { + ret := _m.Called(ctx, call, blockNumber) + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, ethereum.CallMsg, *big.Int) ([]byte, error)); ok { + return rf(ctx, call, blockNumber) + } + if rf, ok := ret.Get(0).(func(context.Context, ethereum.CallMsg, *big.Int) []byte); ok { + r0 = rf(ctx, call, blockNumber) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, ethereum.CallMsg, *big.Int) error); ok { + r1 = rf(ctx, call, blockNumber) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CodeAt provides a mock function with given fields: ctx, contract, blockNumber +func (_m *L2Mock) CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error) { + ret := _m.Called(ctx, contract, blockNumber) + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, common.Address, *big.Int) ([]byte, error)); ok { + return rf(ctx, contract, blockNumber) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Address, *big.Int) []byte); ok { + r0 = rf(ctx, contract, blockNumber) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Address, *big.Int) error); ok { + r1 = rf(ctx, contract, blockNumber) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// EstimateGas provides a mock function with given fields: ctx, call +func (_m *L2Mock) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error) { + ret := _m.Called(ctx, call) + + var r0 uint64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, ethereum.CallMsg) (uint64, error)); ok { + return rf(ctx, call) + } + if rf, ok := ret.Get(0).(func(context.Context, ethereum.CallMsg) uint64); ok { + r0 = rf(ctx, call) + } else { + r0 = ret.Get(0).(uint64) + } + + if rf, ok := ret.Get(1).(func(context.Context, ethereum.CallMsg) error); ok { + r1 = rf(ctx, call) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// FilterLogs provides a mock function with given fields: ctx, q +func (_m *L2Mock) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error) { + ret := _m.Called(ctx, q) + + var r0 []types.Log + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, ethereum.FilterQuery) ([]types.Log, error)); ok { + return rf(ctx, q) + } + if rf, ok := ret.Get(0).(func(context.Context, ethereum.FilterQuery) []types.Log); ok { + r0 = rf(ctx, q) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Log) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, ethereum.FilterQuery) error); ok { + r1 = rf(ctx, q) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// HeaderByHash provides a mock function with given fields: ctx, hash +func (_m *L2Mock) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) { + ret := _m.Called(ctx, hash) + + var r0 *types.Header + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, common.Hash) (*types.Header, error)); ok { + return rf(ctx, hash) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Hash) *types.Header); ok { + r0 = rf(ctx, hash) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Header) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Hash) error); ok { + r1 = rf(ctx, hash) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// HeaderByNumber provides a mock function with given fields: ctx, number +func (_m *L2Mock) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) { + ret := _m.Called(ctx, number) + + var r0 *types.Header + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *big.Int) (*types.Header, error)); ok { + return rf(ctx, number) + } + if rf, ok := ret.Get(0).(func(context.Context, *big.Int) *types.Header); ok { + r0 = rf(ctx, number) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Header) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *big.Int) error); ok { + r1 = rf(ctx, number) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// PendingCodeAt provides a mock function with given fields: ctx, account +func (_m *L2Mock) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) { + ret := _m.Called(ctx, account) + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, common.Address) ([]byte, error)); ok { + return rf(ctx, account) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Address) []byte); ok { + r0 = rf(ctx, account) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Address) error); ok { + r1 = rf(ctx, account) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// PendingNonceAt provides a mock function with given fields: ctx, account +func (_m *L2Mock) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) { + ret := _m.Called(ctx, account) + + var r0 uint64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, common.Address) (uint64, error)); ok { + return rf(ctx, account) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Address) uint64); ok { + r0 = rf(ctx, account) + } else { + r0 = ret.Get(0).(uint64) + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Address) error); ok { + r1 = rf(ctx, account) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SendTransaction provides a mock function with given fields: ctx, tx +func (_m *L2Mock) SendTransaction(ctx context.Context, tx *types.Transaction) error { + ret := _m.Called(ctx, tx) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *types.Transaction) error); ok { + r0 = rf(ctx, tx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// SubscribeFilterLogs provides a mock function with given fields: ctx, q, ch +func (_m *L2Mock) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) { + ret := _m.Called(ctx, q, ch) + + var r0 ethereum.Subscription + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, ethereum.FilterQuery, chan<- types.Log) (ethereum.Subscription, error)); ok { + return rf(ctx, q, ch) + } + if rf, ok := ret.Get(0).(func(context.Context, ethereum.FilterQuery, chan<- types.Log) ethereum.Subscription); ok { + r0 = rf(ctx, q, ch) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(ethereum.Subscription) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, ethereum.FilterQuery, chan<- types.Log) error); ok { + r1 = rf(ctx, q, ch) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SubscribeNewHead provides a mock function with given fields: ctx, ch +func (_m *L2Mock) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error) { + ret := _m.Called(ctx, ch) + + var r0 ethereum.Subscription + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, chan<- *types.Header) (ethereum.Subscription, error)); ok { + return rf(ctx, ch) + } + if rf, ok := ret.Get(0).(func(context.Context, chan<- *types.Header) ethereum.Subscription); ok { + r0 = rf(ctx, ch) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(ethereum.Subscription) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, chan<- *types.Header) error); ok { + r1 = rf(ctx, ch) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SuggestGasPrice provides a mock function with given fields: ctx +func (_m *L2Mock) SuggestGasPrice(ctx context.Context) (*big.Int, error) { + ret := _m.Called(ctx) + + var r0 *big.Int + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (*big.Int, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) *big.Int); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*big.Int) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SuggestGasTipCap provides a mock function with given fields: ctx +func (_m *L2Mock) SuggestGasTipCap(ctx context.Context) (*big.Int, error) { + ret := _m.Called(ctx) + + var r0 *big.Int + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (*big.Int, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) *big.Int); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*big.Int) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TransactionCount provides a mock function with given fields: ctx, blockHash +func (_m *L2Mock) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error) { + ret := _m.Called(ctx, blockHash) + + var r0 uint + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, common.Hash) (uint, error)); ok { + return rf(ctx, blockHash) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Hash) uint); ok { + r0 = rf(ctx, blockHash) + } else { + r0 = ret.Get(0).(uint) + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Hash) error); ok { + r1 = rf(ctx, blockHash) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TransactionInBlock provides a mock function with given fields: ctx, blockHash, index +func (_m *L2Mock) TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error) { + ret := _m.Called(ctx, blockHash, index) + + var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, common.Hash, uint) (*types.Transaction, error)); ok { + return rf(ctx, blockHash, index) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Hash, uint) *types.Transaction); ok { + r0 = rf(ctx, blockHash, index) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Transaction) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Hash, uint) error); ok { + r1 = rf(ctx, blockHash, index) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +type mockConstructorTestingTNewL2Mock interface { + mock.TestingT + Cleanup(func()) +} + +// NewL2Mock creates a new instance of L2Mock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewL2Mock(t mockConstructorTestingTNewL2Mock) *L2Mock { + mock := &L2Mock{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/l1infotreesync/mock_processor_test.go b/l1infotreesync/mock_processor_test.go new file mode 100644 index 00000000..f7105850 --- /dev/null +++ b/l1infotreesync/mock_processor_test.go @@ -0,0 +1,81 @@ +// Code generated by mockery v2.22.1. DO NOT EDIT. + +package l1infotreesync + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" +) + +// ProcessorMock is an autogenerated mock type for the processorInterface type +type ProcessorMock struct { + mock.Mock +} + +// getLastProcessedBlock provides a mock function with given fields: ctx +func (_m *ProcessorMock) getLastProcessedBlock(ctx context.Context) (uint64, error) { + ret := _m.Called(ctx) + + var r0 uint64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (uint64, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) uint64); ok { + r0 = rf(ctx) + } else { + r0 = ret.Get(0).(uint64) + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// processBlock provides a mock function with given fields: block +func (_m *ProcessorMock) processBlock(b block) error { + ret := _m.Called(b) + + var r0 error + if rf, ok := ret.Get(0).(func(block) error); ok { + r0 = rf(b) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// reorg provides a mock function with given fields: firstReorgedBlock +func (_m *ProcessorMock) reorg(firstReorgedBlock uint64) error { + ret := _m.Called(firstReorgedBlock) + + var r0 error + if rf, ok := ret.Get(0).(func(uint64) error); ok { + r0 = rf(firstReorgedBlock) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +type mockConstructorTestingTNewProcessorMock interface { + mock.TestingT + Cleanup(func()) +} + +// NewProcessorMock creates a new instance of ProcessorMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewProcessorMock(t mockConstructorTestingTNewProcessorMock) *ProcessorMock { + mock := &ProcessorMock{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/l1infotreesync/mock_reorgdetector_test.go b/l1infotreesync/mock_reorgdetector_test.go new file mode 100644 index 00000000..9737ba06 --- /dev/null +++ b/l1infotreesync/mock_reorgdetector_test.go @@ -0,0 +1,63 @@ +// Code generated by mockery v2.22.1. DO NOT EDIT. + +package l1infotreesync + +import ( + context "context" + + common "github.com/ethereum/go-ethereum/common" + + mock "github.com/stretchr/testify/mock" + + reorgdetector "github.com/0xPolygon/cdk/reorgdetector" +) + +// ReorgDetectorMock is an autogenerated mock type for the ReorgDetector type +type ReorgDetectorMock struct { + mock.Mock +} + +// AddBlockToTrack provides a mock function with given fields: ctx, id, blockNum, blockHash +func (_m *ReorgDetectorMock) AddBlockToTrack(ctx context.Context, id string, blockNum uint64, blockHash common.Hash) error { + ret := _m.Called(ctx, id, blockNum, blockHash) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, uint64, common.Hash) error); ok { + r0 = rf(ctx, id, blockNum, blockHash) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Subscribe provides a mock function with given fields: id +func (_m *ReorgDetectorMock) Subscribe(id string) *reorgdetector.Subscription { + ret := _m.Called(id) + + var r0 *reorgdetector.Subscription + if rf, ok := ret.Get(0).(func(string) *reorgdetector.Subscription); ok { + r0 = rf(id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*reorgdetector.Subscription) + } + } + + return r0 +} + +type mockConstructorTestingTNewReorgDetectorMock interface { + mock.TestingT + Cleanup(func()) +} + +// NewReorgDetectorMock creates a new instance of ReorgDetectorMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewReorgDetectorMock(t mockConstructorTestingTNewReorgDetectorMock) *ReorgDetectorMock { + mock := &ReorgDetectorMock{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/l1infotreesync/processor.go b/l1infotreesync/processor.go new file mode 100644 index 00000000..267ec0b4 --- /dev/null +++ b/l1infotreesync/processor.go @@ -0,0 +1,487 @@ +package l1infotreesync + +import ( + "context" + "encoding/binary" + "encoding/json" + "errors" + + "github.com/0xPolygon/cdk/l1infotree" + "github.com/ethereum/go-ethereum/common" + "github.com/ledgerwatch/erigon-lib/kv" + "github.com/ledgerwatch/erigon-lib/kv/mdbx" + "golang.org/x/crypto/sha3" +) + +const ( + rootTable = "l1infotreesync-root" + indexTable = "l1infotreesync-index" + infoTable = "l1infotreesync-info" + blockTable = "l1infotreesync-block" + lastBlockTable = "l1infotreesync-lastBlock" +) + +var ( + ErrBlockNotProcessed = errors.New("given block(s) have not been processed yet") + ErrNotFound = errors.New("not found") + lastBlokcKey = []byte("lb") +) + +type processor struct { + db kv.RwDB + tree *l1infotree.L1InfoTree +} + +type L1InfoTreeLeaf struct { + L1InfoTreeRoot common.Hash + L1InfoTreeIndex uint32 + PreviousBlockHash common.Hash + BlockNumber uint64 + Timestamp uint64 + MainnetExitRoot common.Hash + RollupExitRoot common.Hash + GlobalExitRoot common.Hash +} + +type storeLeaf struct { + MainnetExitRoot common.Hash + RollupExitRoot common.Hash + ParentHash common.Hash + InfoRoot common.Hash + Index uint32 + Timestamp uint64 + BlockNumber uint64 +} + +type blockWithLeafs struct { + // inclusive + firstIndex uint32 + // not inclusive + lastIndex uint32 +} + +func (l *storeLeaf) GlobalExitRoot() common.Hash { + var gerBytes [32]byte + hasher := sha3.NewLegacyKeccak256() + hasher.Write(l.MainnetExitRoot[:]) + hasher.Write(l.RollupExitRoot[:]) + copy(gerBytes[:], hasher.Sum(nil)) + return gerBytes +} + +func tableCfgFunc(defaultBuckets kv.TableCfg) kv.TableCfg { + return kv.TableCfg{ + rootTable: {}, + indexTable: {}, + infoTable: {}, + blockTable: {}, + lastBlockTable: {}, + } +} + +func newProcessor(ctx context.Context, dbPath string, treeHeight uint8) (*processor, error) { + db, err := mdbx.NewMDBX(nil). + Path(dbPath). + WithTableCfg(tableCfgFunc). + Open() + if err != nil { + return nil, err + } + p := &processor{ + db: db, + } + leaves, err := p.getAllLeavesHashed(ctx) + if err != nil { + return nil, err + } + tree, err := l1infotree.NewL1InfoTree(treeHeight, leaves) + if err != nil { + return nil, err + } + p.tree = tree + return p, nil +} + +func (p *processor) getAllLeavesHashed(ctx context.Context) ([][32]byte, error) { + // TODO: same coment about refactor that appears at ComputeMerkleProofByIndex + tx, err := p.db.BeginRo(ctx) + if err != nil { + return nil, err + } + defer tx.Rollback() + + index, err := p.getLastIndex(tx) + if err == ErrNotFound { + return nil, nil + } + if err != nil { + return nil, err + } + + return p.getHasedLeaves(tx, index) +} + +func (p *processor) ComputeMerkleProofByIndex(ctx context.Context, index uint32) ([][32]byte, common.Hash, error) { + // TODO: refactor the tree to store the nodes so it's not neede to load all the leaves and compute the tree + // every time this function is called. Since it's not a sparse MT, an alternative could be to store the proofs + // as part of the info + tx, err := p.db.BeginRo(ctx) + if err != nil { + return nil, common.Hash{}, err + } + defer tx.Rollback() + + leaves, err := p.getHasedLeaves(tx, index) + if err != nil { + return nil, common.Hash{}, err + } + return p.tree.ComputeMerkleProof(index, leaves) +} + +func (p *processor) getHasedLeaves(tx kv.Tx, untilIndex uint32) ([][32]byte, error) { + leaves := [][32]byte{} + for i := uint32(0); i <= untilIndex; i++ { + info, err := p.getInfoByIndexWithTx(tx, i) + if err != nil { + return nil, err + } + h := l1infotree.HashLeafData(info.GlobalExitRoot, info.PreviousBlockHash, info.Timestamp) + leaves = append(leaves, h) + } + return leaves, nil +} + +func (p *processor) ComputeMerkleProofByRoot(ctx context.Context, root common.Hash) ([][32]byte, common.Hash, error) { + info, err := p.GetInfoByRoot(ctx, root) + if err != nil { + return nil, common.Hash{}, err + } + return p.ComputeMerkleProofByIndex(ctx, info.L1InfoTreeIndex) +} + +func (p *processor) GetInfoByRoot(ctx context.Context, root common.Hash) (*L1InfoTreeLeaf, error) { + tx, err := p.db.BeginRo(ctx) + if err != nil { + return nil, err + } + defer tx.Rollback() + hash, err := tx.GetOne(rootTable, root[:]) + if err != nil { + return nil, err + } + if hash == nil { + return nil, ErrNotFound + } + return p.getInfoByHashWithTx(tx, hash) +} + +// GetLatestInfoUntilBlock returns the most recent L1InfoTreeLeaf that occured before or at blockNum +func (p *processor) GetLatestInfoUntilBlock(ctx context.Context, blockNum uint64) (*L1InfoTreeLeaf, error) { + tx, err := p.db.BeginRo(ctx) + if err != nil { + return nil, err + } + defer tx.Rollback() + lpb, err := p.getLastProcessedBlockWithTx(tx) + if lpb < blockNum { + return nil, ErrBlockNotProcessed + } + c, err := tx.Cursor(blockTable) + if err != nil { + return nil, err + } + defer c.Close() + for k, v, err := c.Seek(uint64ToBytes(blockNum)); k != nil; k, v, err = c.Prev() { + if err != nil { + return nil, err + } + if bytes2Uint64(k) > blockNum { + // Seek function returns matching key or greater, therefore + // we could bed ealing with a block number greater than expected + continue + } + blk := blockWithLeafs{} + if err := json.Unmarshal(v, &blk); err != nil { + return nil, err + } + hash, err := tx.GetOne(indexTable, uint32ToBytes(blk.lastIndex-1)) + if err != nil { + return nil, err + } + return p.getInfoByHashWithTx(tx, hash) + } + + return nil, ErrNotFound +} + +func (p *processor) GetInfoByIndex(ctx context.Context, index uint32) (*L1InfoTreeLeaf, error) { + tx, err := p.db.BeginRo(ctx) + if err != nil { + return nil, err + } + defer tx.Rollback() + return p.getInfoByIndexWithTx(tx, index) +} + +func (p *processor) getInfoByIndexWithTx(tx kv.Tx, index uint32) (*L1InfoTreeLeaf, error) { + hash, err := tx.GetOne(rootTable, uint32ToBytes(index)) + if err != nil { + return nil, err + } + if hash == nil { + return nil, ErrNotFound + } + return p.getInfoByHashWithTx(tx, hash) +} + +func (p *processor) GetInfoByHash(ctx context.Context, hash []byte) (*L1InfoTreeLeaf, error) { + tx, err := p.db.BeginRo(ctx) + if err != nil { + return nil, err + } + defer tx.Rollback() + return p.getInfoByHashWithTx(tx, hash) +} + +func (p *processor) getInfoByHashWithTx(tx kv.Tx, hash []byte) (*L1InfoTreeLeaf, error) { + infoBytes, err := tx.GetOne(infoTable, hash) + if err != nil { + return nil, err + } + if infoBytes == nil { + return nil, ErrNotFound + } + var info storeLeaf + if err := json.Unmarshal(infoBytes, &info); err != nil { + return nil, err + } + + return &L1InfoTreeLeaf{ + L1InfoTreeRoot: info.InfoRoot, + L1InfoTreeIndex: info.Index, + PreviousBlockHash: info.ParentHash, + BlockNumber: info.BlockNumber, + Timestamp: info.Timestamp, + MainnetExitRoot: info.MainnetExitRoot, + RollupExitRoot: info.RollupExitRoot, + GlobalExitRoot: info.GlobalExitRoot(), + }, nil +} + +func (p *processor) getLastProcessedBlock(ctx context.Context) (uint64, error) { + tx, err := p.db.BeginRo(ctx) + if err != nil { + return 0, err + } + defer tx.Rollback() + return p.getLastProcessedBlockWithTx(tx) +} + +func (p *processor) getLastProcessedBlockWithTx(tx kv.Tx) (uint64, error) { + if blockNumBytes, err := tx.GetOne(lastBlockTable, lastBlokcKey); err != nil { + return 0, err + } else if blockNumBytes == nil { + return 0, nil + } else { + return bytes2Uint64(blockNumBytes), nil + } +} + +func (p *processor) reorg(firstReorgedBlock uint64) error { + // TODO: Does tree need to be reorged? + tx, err := p.db.BeginRw(context.Background()) + if err != nil { + return err + } + c, err := tx.Cursor(blockTable) + if err != nil { + return err + } + defer c.Close() + firstKey := uint64ToBytes(firstReorgedBlock) + for blkKey, blkValue, err := c.Seek(firstKey); blkKey != nil; blkKey, blkValue, err = c.Next() { + if err != nil { + tx.Rollback() + return err + } + var blk blockWithLeafs + if err := json.Unmarshal(blkValue, &blk); err != nil { + tx.Rollback() + return err + } + for i := blk.firstIndex; i < blk.lastIndex; i++ { + if err := p.deleteLeaf(tx, i); err != nil { + tx.Rollback() + return err + } + } + if err := tx.Delete(blockTable, blkKey); err != nil { + tx.Rollback() + return err + } + } + if err := p.updateLastProcessedBlock(tx, firstReorgedBlock-1); err != nil { + tx.Rollback() + return err + } + return tx.Commit() +} + +func (p *processor) deleteLeaf(tx kv.RwTx, index uint32) error { + // TODO: do we need to do something with p.tree here? + // Get leaf info to delete all relations + hash, err := tx.GetOne(indexTable, uint32ToBytes(index)) + if err != nil { + return err + } + if hash == nil { + return ErrNotFound + } + infoBytes, err := tx.GetOne(infoTable, hash) + if err != nil { + return err + } + if infoBytes == nil { + return ErrNotFound + } + var info storeLeaf + if err := json.Unmarshal(infoBytes, &info); err != nil { + return err + } + + // Delete + if err := tx.Delete(rootTable, info.InfoRoot[:]); err != nil { + return err + } + if err := tx.Delete(indexTable, uint32ToBytes(index)); err != nil { + return err + } + if err := tx.Delete(infoTable, hash); err != nil { + return err + } + return nil +} + +// processBlock process the leafs of the L1 info tree found on a block +// this function can be called without leafs with the intention to track the last processed block +func (p *processor) processBlock(b block) error { + tx, err := p.db.BeginRw(context.Background()) + if err != nil { + return err + } + if len(b.Events) > 0 { + lastIndex, err := p.getLastIndex(tx) + if err != nil { + tx.Rollback() + return err + } + initialIndex := lastIndex + 1 + for i, l := range b.Events { + leafToStore := storeLeaf{ + Index: initialIndex + uint32(i), + MainnetExitRoot: l.MainnetExitRoot, + RollupExitRoot: l.RollupExitRoot, + ParentHash: b.ParentHash, + Timestamp: b.Timestamp, + BlockNumber: b.Num, + } + if err := p.addLeaf(tx, leafToStore); err != nil { + tx.Rollback() + return err + } + } + bwl := blockWithLeafs{ + firstIndex: initialIndex, + lastIndex: initialIndex + uint32(len(b.Events)), + } + blockValue, err := json.Marshal(bwl) + if err != nil { + tx.Rollback() + return err + } + if err := tx.Put(blockTable, uint64ToBytes(b.Num), blockValue); err != nil { + tx.Rollback() + return err + } + } + if err := p.updateLastProcessedBlock(tx, b.Num); err != nil { + tx.Rollback() + return err + } + return tx.Commit() +} + +func (p *processor) getLastIndex(tx kv.Tx) (uint32, error) { + bNum, err := p.getLastProcessedBlockWithTx(tx) + if err != nil { + return 0, err + } + iter, err := tx.RangeDescend(blockTable, uint64ToBytes(bNum), uint64ToBytes(0), 1) + if err != nil { + return 0, err + } + _, blkBytes, err := iter.Next() + if err != nil { + return 0, err + } + if blkBytes == nil { + return 0, ErrNotFound + } + var blk blockWithLeafs + if err := json.Unmarshal(blkBytes, &blk); err != nil { + return 0, err + } + return blk.lastIndex - 1, nil +} + +func (p *processor) addLeaf(tx kv.RwTx, leaf storeLeaf) error { + // Update tree + hash := l1infotree.HashLeafData(leaf.GlobalExitRoot(), leaf.ParentHash, leaf.Timestamp) + root, err := p.tree.AddLeaf(leaf.Index, hash) + if err != nil { + return err + } + leaf.InfoRoot = root + // store info + leafValue, err := json.Marshal(leaf) + if err != nil { + return err + } + if err := tx.Put(infoTable, hash[:], leafValue); err != nil { + return err + } + // store index relation + if err := tx.Put(indexTable, uint32ToBytes(leaf.Index), hash[:]); err != nil { + return err + } + // store root relation + if err := tx.Put(rootTable, root.Bytes(), hash[:]); err != nil { + return err + } + return nil +} + +func (p *processor) updateLastProcessedBlock(tx kv.RwTx, blockNum uint64) error { + blockNumBytes := uint64ToBytes(blockNum) + return tx.Put(lastBlockTable, lastBlokcKey, blockNumBytes) +} + +func uint64ToBytes(num uint64) []byte { + key := make([]byte, 8) + binary.LittleEndian.PutUint64(key, num) + return key +} + +func bytes2Uint64(key []byte) uint64 { + return binary.LittleEndian.Uint64(key) +} + +func uint32ToBytes(num uint32) []byte { + key := make([]byte, 4) + binary.LittleEndian.PutUint32(key, num) + return key +} + +func bytes2Uint32(key []byte) uint32 { + return binary.LittleEndian.Uint32(key) +} diff --git a/l1infotreesync/processor_test.go b/l1infotreesync/processor_test.go new file mode 100644 index 00000000..949a3fde --- /dev/null +++ b/l1infotreesync/processor_test.go @@ -0,0 +1,373 @@ +package l1infotreesync + +import ( + "context" + "fmt" + "slices" + "testing" + + "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/require" +) + +func TestProceessor(t *testing.T) { + path := t.TempDir() + ctx := context.Background() + p, err := newProcessor(ctx, path, 32) + require.NoError(t, err) + actions := []processAction{ + // processed: ~ + &getLastProcessedBlockAction{ + p: p, + description: "on an empty processor", + ctx: context.Background(), + expectedLastProcessedBlock: 0, + expectedErr: nil, + }, + &reorgAction{ + p: p, + description: "on an empty processor: firstReorgedBlock = 0", + firstReorgedBlock: 0, + expectedErr: nil, + }, + &reorgAction{ + p: p, + description: "on an empty processor: firstReorgedBlock = 1", + firstReorgedBlock: 1, + expectedErr: nil, + }, + &getClaimsAndBridgesAction{ + p: p, + description: "on an empty processor", + ctx: context.Background(), + fromBlock: 0, + toBlock: 2, + expectedEvents: nil, + expectedErr: ErrBlockNotProcessed, + }, + &storeL1InfoTreeUpdatesAction{ + p: p, + description: "block1", + b: block1, + expectedErr: nil, + }, + // processed: block1 + &getLastProcessedBlockAction{ + p: p, + description: "after block1", + ctx: context.Background(), + expectedLastProcessedBlock: 1, + expectedErr: nil, + }, + &getClaimsAndBridgesAction{ + p: p, + description: "after block1: range 0, 2", + ctx: context.Background(), + fromBlock: 0, + toBlock: 2, + expectedEvents: nil, + expectedErr: ErrBlockNotProcessed, + }, + &getClaimsAndBridgesAction{ + p: p, + description: "after block1: range 1, 1", + ctx: context.Background(), + fromBlock: 1, + toBlock: 1, + expectedEvents: block1.Events, + expectedErr: nil, + }, + &reorgAction{ + p: p, + description: "after block1", + firstReorgedBlock: 1, + expectedErr: nil, + }, + // processed: ~ + &getClaimsAndBridgesAction{ + p: p, + description: "after block1 reorged", + ctx: context.Background(), + fromBlock: 0, + toBlock: 2, + expectedEvents: nil, + expectedErr: ErrBlockNotProcessed, + }, + &storeL1InfoTreeUpdatesAction{ + p: p, + description: "block1 (after it's reorged)", + b: block1, + expectedErr: nil, + }, + // processed: block3 + &storeL1InfoTreeUpdatesAction{ + p: p, + description: "block3", + b: block3, + expectedErr: nil, + }, + // processed: block1, block3 + &getLastProcessedBlockAction{ + p: p, + description: "after block3", + ctx: context.Background(), + expectedLastProcessedBlock: 3, + expectedErr: nil, + }, + &getClaimsAndBridgesAction{ + p: p, + description: "after block3: range 2, 2", + ctx: context.Background(), + fromBlock: 2, + toBlock: 2, + expectedEvents: []L1InfoTreeUpdate{}, + expectedErr: nil, + }, + &getClaimsAndBridgesAction{ + p: p, + description: "after block3: range 1, 3", + ctx: context.Background(), + fromBlock: 1, + toBlock: 3, + expectedEvents: append(block1.Events, block3.Events...), + expectedErr: nil, + }, + &reorgAction{ + p: p, + description: "after block3, with value 3", + firstReorgedBlock: 3, + expectedErr: nil, + }, + // processed: block1 + &getLastProcessedBlockAction{ + p: p, + description: "after block3 reorged", + ctx: context.Background(), + expectedLastProcessedBlock: 2, + expectedErr: nil, + }, + &reorgAction{ + p: p, + description: "after block3, with value 2", + firstReorgedBlock: 2, + expectedErr: nil, + }, + &getLastProcessedBlockAction{ + p: p, + description: "after block2 reorged", + ctx: context.Background(), + expectedLastProcessedBlock: 1, + expectedErr: nil, + }, + &storeL1InfoTreeUpdatesAction{ + p: p, + description: "block3 after reorg", + b: block3, + expectedErr: nil, + }, + // processed: block1, block3 + &storeL1InfoTreeUpdatesAction{ + p: p, + description: "block4", + b: block4, + expectedErr: nil, + }, + // processed: block1, block3, block4 + &storeL1InfoTreeUpdatesAction{ + p: p, + description: "block5", + b: block5, + expectedErr: nil, + }, + // processed: block1, block3, block4, block5 + &getLastProcessedBlockAction{ + p: p, + description: "after block5", + ctx: context.Background(), + expectedLastProcessedBlock: 5, + expectedErr: nil, + }, + &getClaimsAndBridgesAction{ + p: p, + description: "after block5: range 1, 3", + ctx: context.Background(), + fromBlock: 1, + toBlock: 3, + expectedEvents: append(block1.Events, block3.Events...), + expectedErr: nil, + }, + &getClaimsAndBridgesAction{ + p: p, + description: "after block5: range 4, 5", + ctx: context.Background(), + fromBlock: 4, + toBlock: 5, + expectedEvents: append(block4.Events, block5.Events...), + expectedErr: nil, + }, + &getClaimsAndBridgesAction{ + p: p, + description: "after block5: range 0, 5", + ctx: context.Background(), + fromBlock: 0, + toBlock: 5, + expectedEvents: slices.Concat( + block1.Events, + block3.Events, + block4.Events, + block5.Events, + ), + expectedErr: nil, + }, + } + + for _, a := range actions { + t.Run(fmt.Sprintf("%s: %s", a.method(), a.desc()), a.execute) + } +} + +// BOILERPLATE + +// blocks + +var ( + block1 = block{ + blockHeader: blockHeader{ + Num: 1, + Hash: common.HexToHash("01"), + }, + Events: []L1InfoTreeUpdate{ + {RollupExitRoot: common.HexToHash("01")}, + {MainnetExitRoot: common.HexToHash("01")}, + }, + } + block3 = block{ + blockHeader: blockHeader{ + Num: 3, + Hash: common.HexToHash("02"), + }, + Events: []L1InfoTreeUpdate{ + {RollupExitRoot: common.HexToHash("02"), MainnetExitRoot: common.HexToHash("02")}, + }, + } + block4 = block{ + blockHeader: blockHeader{ + Num: 4, + Hash: common.HexToHash("03"), + }, + Events: []L1InfoTreeUpdate{}, + } + block5 = block{ + blockHeader: blockHeader{ + Num: 5, + Hash: common.HexToHash("04"), + }, + Events: []L1InfoTreeUpdate{ + {RollupExitRoot: common.HexToHash("04")}, + {MainnetExitRoot: common.HexToHash("05")}, + }, + } +) + +// actions + +type processAction interface { + method() string + desc() string + execute(t *testing.T) +} + +// GetClaimsAndBridges + +type getClaimsAndBridgesAction struct { + p *processor + description string + ctx context.Context + fromBlock uint64 + toBlock uint64 + expectedEvents []L1InfoTreeUpdate + expectedErr error +} + +func (a *getClaimsAndBridgesAction) method() string { + return "GetClaimsAndBridges" +} + +func (a *getClaimsAndBridgesAction) desc() string { + return a.description +} + +func (a *getClaimsAndBridgesAction) execute(t *testing.T) { + // TODO: add relevant getters + // actualEvents, actualErr := a.p.GetClaimsAndBridges(a.ctx, a.fromBlock, a.toBlock) + // require.Equal(t, a.expectedEvents, actualEvents) + // require.Equal(t, a.expectedErr, actualErr) +} + +// getLastProcessedBlock + +type getLastProcessedBlockAction struct { + p *processor + description string + ctx context.Context + expectedLastProcessedBlock uint64 + expectedErr error +} + +func (a *getLastProcessedBlockAction) method() string { + return "getLastProcessedBlock" +} + +func (a *getLastProcessedBlockAction) desc() string { + return a.description +} + +func (a *getLastProcessedBlockAction) execute(t *testing.T) { + actualLastProcessedBlock, actualErr := a.p.getLastProcessedBlock(a.ctx) + require.Equal(t, a.expectedLastProcessedBlock, actualLastProcessedBlock) + require.Equal(t, a.expectedErr, actualErr) +} + +// reorg + +type reorgAction struct { + p *processor + description string + firstReorgedBlock uint64 + expectedErr error +} + +func (a *reorgAction) method() string { + return "reorg" +} + +func (a *reorgAction) desc() string { + return a.description +} + +func (a *reorgAction) execute(t *testing.T) { + actualErr := a.p.reorg(a.firstReorgedBlock) + require.Equal(t, a.expectedErr, actualErr) +} + +// storeL1InfoTreeUpdates + +type storeL1InfoTreeUpdatesAction struct { + p *processor + description string + b block + expectedErr error +} + +func (a *storeL1InfoTreeUpdatesAction) method() string { + return "storeL1InfoTreeUpdates" +} + +func (a *storeL1InfoTreeUpdatesAction) desc() string { + return a.description +} + +func (a *storeL1InfoTreeUpdatesAction) execute(t *testing.T) { + actualErr := a.p.processBlock(a.b) + require.Equal(t, a.expectedErr, actualErr) +} diff --git a/test/Makefile b/test/Makefile index 3511b4f7..151f7336 100644 --- a/test/Makefile +++ b/test/Makefile @@ -2,6 +2,7 @@ generate-mocks: $(MAKE) generate-mocks-localbridgesync $(MAKE) generate-mocks-reorgdetector + $(MAKE) generate-mocks-l1infotreesync .PHONY: generate-mocks-localbridgesync generate-mocks-localbridgesync: ## Generates mocks for localbridgesync, using mockery tool @@ -37,3 +38,9 @@ help: ## Prints this help @grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ | sort \ | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' +.PHONY: generate-mocks-l1infotreesync +generate-mocks-l1infotreesync: ## Generates mocks for l1infotreesync , using mockery tool + export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=EthClienter --dir=../l1infotreesync --output=../l1infotreesync --outpkg=l1infotreesync --inpackage --structname=L2Mock --filename=mock_l2_test.go + export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=downloaderFull --dir=../l1infotreesync --output=../l1infotreesync --outpkg=l1infotreesync --inpackage --structname=DownloaderMock --filename=mock_downloader_test.go + export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=processorInterface --dir=../l1infotreesync --output=../l1infotreesync --outpkg=l1infotreesync --inpackage --structname=ProcessorMock --filename=mock_processor_test.go + export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=ReorgDetector --dir=../l1infotreesync --output=../l1infotreesync --outpkg=l1infotreesync --inpackage --structname=ReorgDetectorMock --filename=mock_reorgdetector_test.go From 73128ae76551d1fa18065e75de77afeb48cb5f01 Mon Sep 17 00:00:00 2001 From: Arnau Date: Wed, 24 Jul 2024 17:51:10 +0200 Subject: [PATCH 02/18] WIP --- aggoracle/chaingersender/evm.go | 114 ++++++++++++++++++++++++ aggoracle/e2e_test.go | 147 +++++++++++++++++++++++++++++++ aggoracle/oracle.go | 100 +++++++++++++++++++++ go.mod | 6 +- go.sum | 12 +-- l1infotreesync/downloader.go | 7 +- l1infotreesync/e2e_test.go | 30 +++++-- l1infotreesync/l1infotreesync.go | 4 +- l1infotreesync/processor.go | 29 +++--- 9 files changed, 413 insertions(+), 36 deletions(-) create mode 100644 aggoracle/chaingersender/evm.go create mode 100644 aggoracle/e2e_test.go create mode 100644 aggoracle/oracle.go diff --git a/aggoracle/chaingersender/evm.go b/aggoracle/chaingersender/evm.go new file mode 100644 index 00000000..c7860528 --- /dev/null +++ b/aggoracle/chaingersender/evm.go @@ -0,0 +1,114 @@ +package chaingersender + +import ( + "context" + "fmt" + "math/big" + "time" + + "github.com/0xPolygon/cdk-contracts-tooling/contracts/manual/pessimisticglobalexitroot" + "github.com/0xPolygon/cdk/log" + "github.com/0xPolygonHermez/zkevm-ethtx-manager/ethtxmanager" + "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" +) + +var ( + waitPeriodMonitorTx = time.Second * 5 +) + +type EthClienter interface { + ethereum.LogFilterer + ethereum.BlockNumberReader + ethereum.ChainReader + bind.ContractBackend +} + +type EthTxManager interface { + Remove(ctx context.Context, id common.Hash) error + ResultsByStatus(ctx context.Context, statuses []ethtxmanager.MonitoredTxStatus) ([]ethtxmanager.MonitoredTxResult, error) + Result(ctx context.Context, id common.Hash) (ethtxmanager.MonitoredTxResult, error) + Add(ctx context.Context, to *common.Address, forcedNonce *uint64, value *big.Int, data []byte, gasOffset uint64, sidecar *types.BlobTxSidecar) (common.Hash, error) +} + +type EVMChainGERSender struct { + gerContract *pessimisticglobalexitroot.Pessimisticglobalexitroot + gerAddr common.Address + sender common.Address + client EthClienter + ethTxMan EthTxManager + gasOffset uint64 +} + +func NewEVMChainGERSender( + globalExitRoot, sender common.Address, + client EthClienter, + ethTxMan EthTxManager, + gasOffset uint64, +) (*EVMChainGERSender, error) { + gerContract, err := pessimisticglobalexitroot.NewPessimisticglobalexitroot(globalExitRoot, client) + if err != nil { + return nil, err + } + return &EVMChainGERSender{ + gerContract: gerContract, + gerAddr: globalExitRoot, + sender: sender, + client: client, + ethTxMan: ethTxMan, + gasOffset: gasOffset, + }, nil +} + +func (c *EVMChainGERSender) IsGERAlreadyInjected(ger common.Hash) (bool, error) { + timestamp, err := c.gerContract.GlobalExitRootMap(&bind.CallOpts{Pending: false}, ger) + if err != nil { + return false, err + } + return timestamp.Cmp(big.NewInt(0)) == 0, nil +} + +func (c *EVMChainGERSender) UpdateGERWaitUntilMined(ctx context.Context, ger common.Hash) error { + opts := &bind.TransactOpts{ + From: c.sender, + // Hardcode dummy values to avoid calls to the client, + // ethtxmanager is going to handle that + NoSend: true, + Nonce: big.NewInt(1), + GasLimit: 1, + GasPrice: big.NewInt(1), + } + tx, err := c.gerContract.UpdateGlobalExitRoot(opts, ger) + if err != nil { + return err + } + id, err := c.ethTxMan.Add(ctx, &c.gerAddr, nil, big.NewInt(0), tx.Data(), c.gasOffset, nil) + if err != nil { + return err + } + for { + time.Sleep(waitPeriodMonitorTx) + res, err := c.ethTxMan.Result(ctx, id) + if err != nil { + log.Error("error calling ethTxMan.Result: ", err) + } + switch res.Status { + case ethtxmanager.MonitoredTxStatusCreated: + continue + case ethtxmanager.MonitoredTxStatusSent: + continue + case ethtxmanager.MonitoredTxStatusFailed: + return fmt.Errorf("tx %s failed", res.ID) + case ethtxmanager.MonitoredTxStatusMined: + return nil + case ethtxmanager.MonitoredTxStatusSafe: + return nil + case ethtxmanager.MonitoredTxStatusFinalized: + return nil + default: + log.Error("unexpected tx status: ", res.Status) + } + } +} diff --git a/aggoracle/e2e_test.go b/aggoracle/e2e_test.go new file mode 100644 index 00000000..04d16cb0 --- /dev/null +++ b/aggoracle/e2e_test.go @@ -0,0 +1,147 @@ +package aggoracle_test + +import ( + "context" + "math/big" + "strconv" + "testing" + "time" + + "github.com/0xPolygon/cdk-contracts-tooling/contracts/manual/globalexitrootnopush0" + "github.com/0xPolygon/cdk-contracts-tooling/contracts/manual/pessimisticglobalexitroot" + "github.com/0xPolygon/cdk/aggoracle" + "github.com/0xPolygon/cdk/aggoracle/chaingersender" + "github.com/0xPolygon/cdk/etherman" + "github.com/0xPolygon/cdk/l1infotreesync" + "github.com/0xPolygon/cdk/reorgdetector" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethclient/simulated" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" +) + +func TestEVM(t *testing.T) { + ctx := context.Background() + l1Client, syncer, gerL1Contract, authL1 := commonSetup(t) + sender := evmSetup(t) + oracle, err := aggoracle.New(sender, l1Client.Client(), syncer, etherman.LatestBlock) + require.NoError(t, err) + oracle.Start(ctx) + + runTest(t, gerL1Contract, sender, l1Client, authL1) +} + +func commonSetup(t *testing.T) ( + *simulated.Backend, + *l1infotreesync.L1InfoTreeSync, + *globalexitrootnopush0.Globalexitrootnopush0, + *bind.TransactOpts, +) { + // Config and spin up + ctx := context.Background() + // Simulated L1 + privateKeyL1, err := crypto.GenerateKey() + require.NoError(t, err) + authL1, err := bind.NewKeyedTransactorWithChainID(privateKeyL1, big.NewInt(1337)) + require.NoError(t, err) + l1Client, gerL1Addr, gerL1Contract, err := newSimulatedL1(authL1) + require.NoError(t, err) + // Reorg detector + rdm := NewReorgDetectorMock(t) + rdm.On("Subscribe", mock.Anything).Return(&reorgdetector.Subscription{}) + rdm.On("AddBlockToTrack", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) + reorg, err := reorgdetector.New(ctx) + require.NoError(t, err) + // Syncer + dbPath := t.TempDir() + syncer, err := l1infotreesync.New(ctx, dbPath, gerL1Addr, 10, etherman.LatestBlock, reorg, l1Client.Client(), 32) + require.NoError(t, err) + syncer.Sync(ctx) + + return l1Client, syncer, gerL1Contract, authL1 +} + +func evmSetup(t *testing.T) aggoracle.ChainSender { + privateKeyL2, err := crypto.GenerateKey() + require.NoError(t, err) + authL2, err := bind.NewKeyedTransactorWithChainID(privateKeyL2, big.NewInt(1337)) + require.NoError(t, err) + l2Client, gerL2Addr, _, err := newSimulatedEVMAggSovereignChain(authL2) + require.NoError(t, err) + sender, err := chaingersender.NewEVMChainGERSender(gerL2Addr, authL2.From, l2Client.Client(), nil, 0) + require.NoError(t, err) + + return sender +} + +func newSimulatedL1(auth *bind.TransactOpts) ( + client *simulated.Backend, + gerAddr common.Address, + gerContract *globalexitrootnopush0.Globalexitrootnopush0, + err error, +) { + balance, _ := new(big.Int).SetString("10000000000000000000000000", 10) //nolint:gomnd + address := auth.From + genesisAlloc := map[common.Address]types.Account{ + address: { + Balance: balance, + }, + } + blockGasLimit := uint64(999999999999999999) //nolint:gomnd + client = simulated.NewBackend(genesisAlloc, simulated.WithBlockGasLimit(blockGasLimit)) + + gerAddr, _, gerContract, err = globalexitrootnopush0.DeployGlobalexitrootnopush0(auth, client.Client(), auth.From, auth.From) + + client.Commit() + return +} + +func newSimulatedEVMAggSovereignChain(auth *bind.TransactOpts) ( + client *simulated.Backend, + gerAddr common.Address, + gerContract *pessimisticglobalexitroot.Pessimisticglobalexitroot, + err error, +) { + balance, _ := new(big.Int).SetString("10000000000000000000000000", 10) //nolint:gomnd + address := auth.From + genesisAlloc := map[common.Address]types.Account{ + address: { + Balance: balance, + }, + } + blockGasLimit := uint64(999999999999999999) //nolint:gomnd + client = simulated.NewBackend(genesisAlloc, simulated.WithBlockGasLimit(blockGasLimit)) + + gerAddr, _, gerContract, err = pessimisticglobalexitroot.DeployPessimisticglobalexitroot(auth, client.Client(), auth.From) + + client.Commit() + return +} + +func runTest( + t *testing.T, + gerL1Contract *globalexitrootnopush0.Globalexitrootnopush0, + sender aggoracle.ChainSender, + l1Client *simulated.Backend, + authL1 *bind.TransactOpts, +) { + for i := 0; i < 10; i++ { + _, err := gerL1Contract.UpdateExitRoot(authL1, common.HexToHash(strconv.Itoa(i))) + require.NoError(t, err) + l1Client.Commit() + time.Sleep(time.Second * 30) + expectedGER, err := gerL1Contract.GetLastGlobalExitRoot(&bind.CallOpts{Pending: false}) + require.NoError(t, err) + isInjected, err := sender.IsGERAlreadyInjected(expectedGER) + require.NoError(t, err) + require.True(t, isInjected) + } +} + +type ReorgDetector interface { + Subscribe(id string) *reorgdetector.Subscription + AddBlockToTrack(ctx context.Context, id string, blockNum uint64, blockHash common.Hash) error +} diff --git a/aggoracle/oracle.go b/aggoracle/oracle.go new file mode 100644 index 00000000..0e89a7f2 --- /dev/null +++ b/aggoracle/oracle.go @@ -0,0 +1,100 @@ +package aggoracle + +import ( + "context" + "math/big" + "time" + + "github.com/0xPolygon/cdk/etherman" + "github.com/0xPolygon/cdk/l1infotreesync" + "github.com/0xPolygon/cdk/log" + "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" +) + +var ( + waitPeriodNextGER = time.Second * 30 +) + +type EthClienter interface { + ethereum.LogFilterer + ethereum.BlockNumberReader + ethereum.ChainReader + bind.ContractBackend +} + +type L1InfoTreer interface { + GetLatestInfoUntilBlock(ctx context.Context, blockNum uint64) (*l1infotreesync.L1InfoTreeLeaf, error) +} + +type ChainSender interface { + IsGERAlreadyInjected(ger common.Hash) (bool, error) + UpdateGERWaitUntilMined(ctx context.Context, ger common.Hash) error +} + +type AggOracle struct { + ticker *time.Ticker + l1Client EthClienter + l1Info L1InfoTreer + chainSender ChainSender + blockFinality *big.Int +} + +func New( + chainSender ChainSender, + l1Client EthClienter, + l1InfoTreeSyncer L1InfoTreer, + blockFinalityType etherman.BlockNumberFinality, +) (*AggOracle, error) { + ticker := time.NewTicker(waitPeriodNextGER) + finality, err := blockFinalityType.ToBlockNum() + if err != nil { + return nil, err + } + return &AggOracle{ + ticker: ticker, + l1Client: l1Client, + l1Info: l1InfoTreeSyncer, + chainSender: chainSender, + blockFinality: finality, + }, nil +} + +func (a *AggOracle) Start(ctx context.Context) { + for { + select { + case <-a.ticker.C: + gerToInject, err := a.getLastFinalisedGER(ctx) + if err != nil { + log.Error("error calling getLastFinalisedGER: ", err) + continue + } + if alreadyInjectd, err := a.chainSender.IsGERAlreadyInjected(gerToInject); err != nil { + log.Error("error calling isGERAlreadyInjected: ", err) + continue + } else if alreadyInjectd { + log.Debugf("GER %s already injected", gerToInject.Hex()) + continue + } + if err := a.chainSender.UpdateGERWaitUntilMined(ctx, gerToInject); err != nil { + log.Error("error calling updateGERWaitUntilMined: ", err) + continue + } + case <-ctx.Done(): + return + } + } +} + +func (a *AggOracle) getLastFinalisedGER(ctx context.Context) (common.Hash, error) { + header, err := a.l1Client.HeaderByNumber(ctx, a.blockFinality) + if err != nil { + return common.Hash{}, err + } + info, err := a.l1Info.GetLatestInfoUntilBlock(ctx, header.Number.Uint64()) + if err != nil { + return common.Hash{}, err + } + return info.GlobalExitRoot, nil +} diff --git a/go.mod b/go.mod index 1a3673a9..fdcf2398 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,10 @@ module github.com/0xPolygon/cdk go 1.22.4 require ( - github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240627125553-80db9d8a41b5 - github.com/0xPolygon/cdk-data-availability v0.0.8 + github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240724124854-785bb2a0e4a2 + github.com/0xPolygon/cdk-data-availability v0.0.8-0.20240712072318-72ae67613cbf github.com/0xPolygon/cdk-rpc v0.0.0-20240419104226-c0a62ba0f49d - github.com/0xPolygonHermez/zkevm-data-streamer v0.2.2 + github.com/0xPolygonHermez/zkevm-data-streamer v0.2.3-RC4 github.com/0xPolygonHermez/zkevm-ethtx-manager v0.1.9 github.com/0xPolygonHermez/zkevm-synchronizer-l1 v0.6.3-0.20240712085301-0310358abb59 github.com/ethereum/go-ethereum v1.14.5 diff --git a/go.sum b/go.sum index cb15f96d..96887d67 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,11 @@ -github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240627125553-80db9d8a41b5 h1:bezOoVvpQvGvf4aCZQpMPFJGKXhhvktpApr+TsD8rdk= -github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240627125553-80db9d8a41b5/go.mod h1:mFlcEjsm2YBBsu8atHJ3zyVnwM+Z/fMXpVmIJge+WVU= -github.com/0xPolygon/cdk-data-availability v0.0.8 h1:bMmOYZ7Ei683y80ric3KzMPXtRGmchAmfjIRzghaHb4= -github.com/0xPolygon/cdk-data-availability v0.0.8/go.mod h1:3XkZ0zn0GsvAT01MPQMmukF534CVSFmtrcoK3F/BK6Q= +github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240724124854-785bb2a0e4a2 h1:vMRkvTf+sfCKtEDFRGlZ9saDzQIf+LR+ly2OiRyE/2Q= +github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240724124854-785bb2a0e4a2/go.mod h1:mFlcEjsm2YBBsu8atHJ3zyVnwM+Z/fMXpVmIJge+WVU= +github.com/0xPolygon/cdk-data-availability v0.0.8-0.20240712072318-72ae67613cbf h1:VWxVYeDhDURGp8pHR4kq3jwoXRazVHsQLMMIqYsO+Fw= +github.com/0xPolygon/cdk-data-availability v0.0.8-0.20240712072318-72ae67613cbf/go.mod h1:3XkZ0zn0GsvAT01MPQMmukF534CVSFmtrcoK3F/BK6Q= github.com/0xPolygon/cdk-rpc v0.0.0-20240419104226-c0a62ba0f49d h1:sxh6hZ2jF/sxxj2jd5o1vuNNCZjYmn4aRG9SRlVaEFs= github.com/0xPolygon/cdk-rpc v0.0.0-20240419104226-c0a62ba0f49d/go.mod h1:2scWqMMufrQXu7TikDgQ3BsyaKoX8qP26D6E262vSOg= -github.com/0xPolygonHermez/zkevm-data-streamer v0.2.2 h1:XRMTk+W6vtJVGVjuEznfWyNt7HkRkkuSmlN5Y6p60Sc= -github.com/0xPolygonHermez/zkevm-data-streamer v0.2.2/go.mod h1:0QkAXcFa92mFJrCbN3UPUJGJYes851yEgYHLONnaosE= +github.com/0xPolygonHermez/zkevm-data-streamer v0.2.3-RC4 h1:+4K+xSzv0ImbK30B/T9FauNTrTFUmWcNKYhIgwsE4C4= +github.com/0xPolygonHermez/zkevm-data-streamer v0.2.3-RC4/go.mod h1:0QkAXcFa92mFJrCbN3UPUJGJYes851yEgYHLONnaosE= github.com/0xPolygonHermez/zkevm-ethtx-manager v0.1.9 h1:vrAezzwTNke6NroDAltGh1k2AJ6ibmZPBsG0bCltbRc= github.com/0xPolygonHermez/zkevm-ethtx-manager v0.1.9/go.mod h1:pRqfLQVM3nbzdhy3buqjAgcVyNDKAXOHqTSgkwiKpic= github.com/0xPolygonHermez/zkevm-synchronizer-l1 v0.6.3-0.20240712085301-0310358abb59 h1:Qwh92vFEXnpmDggQaZA3648viEQfLdMnAw/WFSY+2i8= diff --git a/l1infotreesync/downloader.go b/l1infotreesync/downloader.go index a8ca4cc2..549e482e 100644 --- a/l1infotreesync/downloader.go +++ b/l1infotreesync/downloader.go @@ -15,11 +15,8 @@ import ( "github.com/ethereum/go-ethereum/crypto" ) -const ( - waitForNewBlocksPeriod = time.Millisecond * 100 -) - var ( + waitForNewBlocksPeriod = time.Millisecond * 100 updateL1InfoTreeSignature = crypto.Keccak256Hash([]byte("UpdateL1InfoTree(bytes32,bytes32)")) ) @@ -201,7 +198,7 @@ func (d *downloaderImplementation) appendLog(b *block, l types.Log) { } b.Events = append(b.Events, L1InfoTreeUpdate{ MainnetExitRoot: l1InfoTreeUpdate.MainnetExitRoot, - RollupExitRoot: l1InfoTreeUpdate.MainnetExitRoot, + RollupExitRoot: l1InfoTreeUpdate.RollupExitRoot, }) default: log.Fatalf("unexpected log %+v", l) diff --git a/l1infotreesync/e2e_test.go b/l1infotreesync/e2e_test.go index 5e97e92a..baad1d53 100644 --- a/l1infotreesync/e2e_test.go +++ b/l1infotreesync/e2e_test.go @@ -2,25 +2,28 @@ package l1infotreesync import ( "context" + "fmt" "math/big" "strconv" "testing" "time" - "github.com/0xPolygon/cdk-contracts-tooling/contracts/elderberry/polygonzkevmglobalexitrootv2" + "github.com/0xPolygon/cdk-contracts-tooling/contracts/manual/globalexitrootnopush0" "github.com/0xPolygon/cdk/etherman" + "github.com/0xPolygon/cdk/reorgdetector" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethclient/simulated" + "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) func newSimulatedClient(auth *bind.TransactOpts) ( client *simulated.Backend, gerAddr common.Address, - gerContract *polygonzkevmglobalexitrootv2.Polygonzkevmglobalexitrootv2, + gerContract *globalexitrootnopush0.Globalexitrootnopush0, err error, ) { balance, _ := new(big.Int).SetString("10000000000000000000000000", 10) //nolint:gomnd @@ -33,13 +36,14 @@ func newSimulatedClient(auth *bind.TransactOpts) ( blockGasLimit := uint64(999999999999999999) //nolint:gomnd client = simulated.NewBackend(genesisAlloc, simulated.WithBlockGasLimit(blockGasLimit)) - gerAddr, _, gerContract, err = polygonzkevmglobalexitrootv2.DeployPolygonzkevmglobalexitrootv2(auth, client.Client(), auth.From, auth.From) + gerAddr, _, gerContract, err = globalexitrootnopush0.DeployGlobalexitrootnopush0(auth, client.Client(), auth.From, auth.From) client.Commit() return } func TestE2E(t *testing.T) { + waitForNewBlocksPeriod = time.Millisecond ctx := context.Background() dbPath := t.TempDir() privateKey, err := crypto.GenerateKey() @@ -47,25 +51,33 @@ func TestE2E(t *testing.T) { auth, err := bind.NewKeyedTransactorWithChainID(privateKey, big.NewInt(1337)) require.NoError(t, err) rdm := NewReorgDetectorMock(t) + rdm.On("Subscribe", reorgDetectorID).Return(&reorgdetector.Subscription{}) + rdm.On("AddBlockToTrack", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) client, gerAddr, gerSc, err := newSimulatedClient(auth) + require.NoError(t, err) syncer, err := New(ctx, dbPath, gerAddr, 10, etherman.LatestBlock, rdm, client.Client(), 32) require.NoError(t, err) go syncer.Sync(ctx) // Update GER 10 times + // TODO: test syncer restart for i := 0; i < 10; i++ { - gerSc.UpdateExitRoot(auth, common.HexToHash(strconv.Itoa(i))) + _, err := gerSc.UpdateExitRoot(auth, common.HexToHash(strconv.Itoa(i))) + require.NoError(t, err) client.Commit() // Let the processor catch up - time.Sleep(time.Millisecond * 100) + time.Sleep(time.Millisecond * 10) - expectedRoot, err := gerSc.GetRoot(nil) + expectedRoot, err := gerSc.GetRoot(&bind.CallOpts{Pending: false}) require.NoError(t, err) - info, err := syncer.GetInfoByRoot(ctx, expectedRoot) + expectedGER, err := gerSc.GetLastGlobalExitRoot(&bind.CallOpts{Pending: false}) require.NoError(t, err) - require.Equal(t, expectedRoot, info.L1InfoTreeRoot) info2, err := syncer.GetInfoByIndex(ctx, uint32(i)) - require.NoError(t, err) + require.NoError(t, err, fmt.Sprintf("index: %d, root: %s", i, common.Bytes2Hex(expectedRoot[:]))) + require.Equal(t, common.Hash(expectedGER), info2.GlobalExitRoot, fmt.Sprintf("index: %d", i)) + info, err := syncer.GetInfoByRoot(ctx, expectedRoot) + require.NoError(t, err, fmt.Sprintf("index: %d, expected root: %s, actual root: %s", i, common.Bytes2Hex(expectedRoot[:]), info2.L1InfoTreeRoot)) + require.Equal(t, common.Hash(expectedRoot), info.L1InfoTreeRoot) require.Equal(t, info, info2) } } diff --git a/l1infotreesync/l1infotreesync.go b/l1infotreesync/l1infotreesync.go index 8a5ffde1..fa04f0e6 100644 --- a/l1infotreesync/l1infotreesync.go +++ b/l1infotreesync/l1infotreesync.go @@ -26,14 +26,14 @@ func New( syncBlockChunkSize uint64, blockFinalityType etherman.BlockNumberFinality, rd ReorgDetector, - l2Client EthClienter, + l1Client EthClienter, treeHeight uint8, ) (*L1InfoTreeSync, error) { p, err := newProcessor(ctx, dbPath, treeHeight) if err != nil { return nil, err } - dwn, err := newDownloader(globalExitRoot, l2Client, syncBlockChunkSize, blockFinalityType) + dwn, err := newDownloader(globalExitRoot, l1Client, syncBlockChunkSize, blockFinalityType) if err != nil { return nil, err } diff --git a/l1infotreesync/processor.go b/l1infotreesync/processor.go index 267ec0b4..12047d77 100644 --- a/l1infotreesync/processor.go +++ b/l1infotreesync/processor.go @@ -55,9 +55,9 @@ type storeLeaf struct { type blockWithLeafs struct { // inclusive - firstIndex uint32 + FirstIndex uint32 // not inclusive - lastIndex uint32 + LastIndex uint32 } func (l *storeLeaf) GlobalExitRoot() common.Hash { @@ -111,7 +111,7 @@ func (p *processor) getAllLeavesHashed(ctx context.Context) ([][32]byte, error) defer tx.Rollback() index, err := p.getLastIndex(tx) - if err == ErrNotFound { + if err == ErrNotFound || index == 0 { return nil, nil } if err != nil { @@ -204,7 +204,7 @@ func (p *processor) GetLatestInfoUntilBlock(ctx context.Context, blockNum uint64 if err := json.Unmarshal(v, &blk); err != nil { return nil, err } - hash, err := tx.GetOne(indexTable, uint32ToBytes(blk.lastIndex-1)) + hash, err := tx.GetOne(indexTable, uint32ToBytes(blk.LastIndex-1)) if err != nil { return nil, err } @@ -224,7 +224,7 @@ func (p *processor) GetInfoByIndex(ctx context.Context, index uint32) (*L1InfoTr } func (p *processor) getInfoByIndexWithTx(tx kv.Tx, index uint32) (*L1InfoTreeLeaf, error) { - hash, err := tx.GetOne(rootTable, uint32ToBytes(index)) + hash, err := tx.GetOne(indexTable, uint32ToBytes(index)) if err != nil { return nil, err } @@ -309,7 +309,7 @@ func (p *processor) reorg(firstReorgedBlock uint64) error { tx.Rollback() return err } - for i := blk.firstIndex; i < blk.lastIndex; i++ { + for i := blk.FirstIndex; i < blk.LastIndex; i++ { if err := p.deleteLeaf(tx, i); err != nil { tx.Rollback() return err @@ -370,12 +370,16 @@ func (p *processor) processBlock(b block) error { return err } if len(b.Events) > 0 { + var initialIndex uint32 lastIndex, err := p.getLastIndex(tx) - if err != nil { + if err == ErrNotFound { + initialIndex = 0 + } else if err != nil { tx.Rollback() return err + } else { + initialIndex = lastIndex + 1 } - initialIndex := lastIndex + 1 for i, l := range b.Events { leafToStore := storeLeaf{ Index: initialIndex + uint32(i), @@ -391,8 +395,8 @@ func (p *processor) processBlock(b block) error { } } bwl := blockWithLeafs{ - firstIndex: initialIndex, - lastIndex: initialIndex + uint32(len(b.Events)), + FirstIndex: initialIndex, + LastIndex: initialIndex + uint32(len(b.Events)), } blockValue, err := json.Marshal(bwl) if err != nil { @@ -416,6 +420,9 @@ func (p *processor) getLastIndex(tx kv.Tx) (uint32, error) { if err != nil { return 0, err } + if bNum == 0 { + return 0, nil + } iter, err := tx.RangeDescend(blockTable, uint64ToBytes(bNum), uint64ToBytes(0), 1) if err != nil { return 0, err @@ -431,7 +438,7 @@ func (p *processor) getLastIndex(tx kv.Tx) (uint32, error) { if err := json.Unmarshal(blkBytes, &blk); err != nil { return 0, err } - return blk.lastIndex - 1, nil + return blk.LastIndex - 1, nil } func (p *processor) addLeaf(tx kv.RwTx, leaf storeLeaf) error { From c7d159a51db63fb146936091f1eff7ae5a7eeaf6 Mon Sep 17 00:00:00 2001 From: Arnau Date: Wed, 24 Jul 2024 18:13:08 +0200 Subject: [PATCH 03/18] WIP --- aggoracle/e2e_test.go | 20 ++++++-------------- aggoracle/oracle.go | 4 +++- l1infotreesync/driver.go | 7 +++++-- l1infotreesync/mock_reorgdetector_test.go | 14 ++++++++++++-- localbridgesync/driver.go | 7 +++++-- localbridgesync/mock_reorgdetector_test.go | 14 ++++++++++++-- reorgdetector/mock_eth_client.go | 19 ++++++------------- 7 files changed, 49 insertions(+), 36 deletions(-) diff --git a/aggoracle/e2e_test.go b/aggoracle/e2e_test.go index 04d16cb0..dcda8662 100644 --- a/aggoracle/e2e_test.go +++ b/aggoracle/e2e_test.go @@ -19,7 +19,6 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethclient/simulated" - "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -29,7 +28,7 @@ func TestEVM(t *testing.T) { sender := evmSetup(t) oracle, err := aggoracle.New(sender, l1Client.Client(), syncer, etherman.LatestBlock) require.NoError(t, err) - oracle.Start(ctx) + go oracle.Start(ctx) runTest(t, gerL1Contract, sender, l1Client, authL1) } @@ -50,16 +49,14 @@ func commonSetup(t *testing.T) ( l1Client, gerL1Addr, gerL1Contract, err := newSimulatedL1(authL1) require.NoError(t, err) // Reorg detector - rdm := NewReorgDetectorMock(t) - rdm.On("Subscribe", mock.Anything).Return(&reorgdetector.Subscription{}) - rdm.On("AddBlockToTrack", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - reorg, err := reorgdetector.New(ctx) + dbPathReorgDetector := t.TempDir() + reorg, err := reorgdetector.New(ctx, l1Client.Client(), dbPathReorgDetector) require.NoError(t, err) // Syncer - dbPath := t.TempDir() - syncer, err := l1infotreesync.New(ctx, dbPath, gerL1Addr, 10, etherman.LatestBlock, reorg, l1Client.Client(), 32) + dbPathSyncer := t.TempDir() + syncer, err := l1infotreesync.New(ctx, dbPathSyncer, gerL1Addr, 10, etherman.LatestBlock, reorg, l1Client.Client(), 32) require.NoError(t, err) - syncer.Sync(ctx) + go syncer.Sync(ctx) return l1Client, syncer, gerL1Contract, authL1 } @@ -140,8 +137,3 @@ func runTest( require.True(t, isInjected) } } - -type ReorgDetector interface { - Subscribe(id string) *reorgdetector.Subscription - AddBlockToTrack(ctx context.Context, id string, blockNum uint64, blockHash common.Hash) error -} diff --git a/aggoracle/oracle.go b/aggoracle/oracle.go index 0e89a7f2..f4957c7a 100644 --- a/aggoracle/oracle.go +++ b/aggoracle/oracle.go @@ -77,10 +77,12 @@ func (a *AggOracle) Start(ctx context.Context) { log.Debugf("GER %s already injected", gerToInject.Hex()) continue } + log.Debugf("injecting new GER: %s", gerToInject.Hex()) if err := a.chainSender.UpdateGERWaitUntilMined(ctx, gerToInject); err != nil { - log.Error("error calling updateGERWaitUntilMined: ", err) + log.Errorf("error calling updateGERWaitUntilMined, when trying to inject GER %s: %v", gerToInject.Hex(), err) continue } + log.Debugf("GER %s injected", gerToInject.Hex()) case <-ctx.Done(): return } diff --git a/l1infotreesync/driver.go b/l1infotreesync/driver.go index 9952f797..c907f681 100644 --- a/l1infotreesync/driver.go +++ b/l1infotreesync/driver.go @@ -32,7 +32,7 @@ type processorInterface interface { } type ReorgDetector interface { - Subscribe(id string) *reorgdetector.Subscription + Subscribe(id string) (*reorgdetector.Subscription, error) AddBlockToTrack(ctx context.Context, id string, blockNum uint64, blockHash common.Hash) error } @@ -41,7 +41,10 @@ func newDriver( processor processorInterface, downloader downloaderFull, ) (*driver, error) { - reorgSub := reorgDetector.Subscribe(reorgDetectorID) + reorgSub, err := reorgDetector.Subscribe(reorgDetectorID) + if err != nil { + return nil, err + } return &driver{ reorgDetector: reorgDetector, reorgSub: reorgSub, diff --git a/l1infotreesync/mock_reorgdetector_test.go b/l1infotreesync/mock_reorgdetector_test.go index 9737ba06..22d174d4 100644 --- a/l1infotreesync/mock_reorgdetector_test.go +++ b/l1infotreesync/mock_reorgdetector_test.go @@ -32,10 +32,14 @@ func (_m *ReorgDetectorMock) AddBlockToTrack(ctx context.Context, id string, blo } // Subscribe provides a mock function with given fields: id -func (_m *ReorgDetectorMock) Subscribe(id string) *reorgdetector.Subscription { +func (_m *ReorgDetectorMock) Subscribe(id string) (*reorgdetector.Subscription, error) { ret := _m.Called(id) var r0 *reorgdetector.Subscription + var r1 error + if rf, ok := ret.Get(0).(func(string) (*reorgdetector.Subscription, error)); ok { + return rf(id) + } if rf, ok := ret.Get(0).(func(string) *reorgdetector.Subscription); ok { r0 = rf(id) } else { @@ -44,7 +48,13 @@ func (_m *ReorgDetectorMock) Subscribe(id string) *reorgdetector.Subscription { } } - return r0 + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 } type mockConstructorTestingTNewReorgDetectorMock interface { diff --git a/localbridgesync/driver.go b/localbridgesync/driver.go index 997fd215..eaeed1c7 100644 --- a/localbridgesync/driver.go +++ b/localbridgesync/driver.go @@ -32,7 +32,7 @@ type processorInterface interface { } type ReorgDetector interface { - Subscribe(id string) *reorgdetector.Subscription + Subscribe(id string) (*reorgdetector.Subscription, error) AddBlockToTrack(ctx context.Context, id string, blockNum uint64, blockHash common.Hash) error } @@ -41,7 +41,10 @@ func newDriver( processor processorInterface, downloader downloaderFull, ) (*driver, error) { - reorgSub := reorgDetector.Subscribe(reorgDetectorID) + reorgSub, err := reorgDetector.Subscribe(reorgDetectorID) + if err != nil { + return nil, err + } return &driver{ reorgDetector: reorgDetector, reorgSub: reorgSub, diff --git a/localbridgesync/mock_reorgdetector_test.go b/localbridgesync/mock_reorgdetector_test.go index d11434a1..3639cb9a 100644 --- a/localbridgesync/mock_reorgdetector_test.go +++ b/localbridgesync/mock_reorgdetector_test.go @@ -32,10 +32,14 @@ func (_m *ReorgDetectorMock) AddBlockToTrack(ctx context.Context, id string, blo } // Subscribe provides a mock function with given fields: id -func (_m *ReorgDetectorMock) Subscribe(id string) *reorgdetector.Subscription { +func (_m *ReorgDetectorMock) Subscribe(id string) (*reorgdetector.Subscription, error) { ret := _m.Called(id) var r0 *reorgdetector.Subscription + var r1 error + if rf, ok := ret.Get(0).(func(string) (*reorgdetector.Subscription, error)); ok { + return rf(id) + } if rf, ok := ret.Get(0).(func(string) *reorgdetector.Subscription); ok { r0 = rf(id) } else { @@ -44,7 +48,13 @@ func (_m *ReorgDetectorMock) Subscribe(id string) *reorgdetector.Subscription { } } - return r0 + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 } type mockConstructorTestingTNewReorgDetectorMock interface { diff --git a/reorgdetector/mock_eth_client.go b/reorgdetector/mock_eth_client.go index add883f6..85376cc4 100644 --- a/reorgdetector/mock_eth_client.go +++ b/reorgdetector/mock_eth_client.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.1. DO NOT EDIT. +// Code generated by mockery v2.22.1. DO NOT EDIT. package reorgdetector @@ -20,10 +20,6 @@ type EthClientMock struct { func (_m *EthClientMock) BlockNumber(ctx context.Context) (uint64, error) { ret := _m.Called(ctx) - if len(ret) == 0 { - panic("no return value specified for BlockNumber") - } - var r0 uint64 var r1 error if rf, ok := ret.Get(0).(func(context.Context) (uint64, error)); ok { @@ -48,10 +44,6 @@ func (_m *EthClientMock) BlockNumber(ctx context.Context) (uint64, error) { func (_m *EthClientMock) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) { ret := _m.Called(ctx, number) - if len(ret) == 0 { - panic("no return value specified for HeaderByNumber") - } - var r0 *types.Header var r1 error if rf, ok := ret.Get(0).(func(context.Context, *big.Int) (*types.Header, error)); ok { @@ -74,12 +66,13 @@ func (_m *EthClientMock) HeaderByNumber(ctx context.Context, number *big.Int) (* return r0, r1 } -// NewEthClientMock creates a new instance of EthClientMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewEthClientMock(t interface { +type mockConstructorTestingTNewEthClientMock interface { mock.TestingT Cleanup(func()) -}) *EthClientMock { +} + +// NewEthClientMock creates a new instance of EthClientMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewEthClientMock(t mockConstructorTestingTNewEthClientMock) *EthClientMock { mock := &EthClientMock{} mock.Mock.Test(t) From 5cc0c6fd11ad41933d6bb0f2b9f77c27d9a036b4 Mon Sep 17 00:00:00 2001 From: Arnau Date: Thu, 25 Jul 2024 09:39:08 +0200 Subject: [PATCH 04/18] WIP --- aggoracle/chaingersender/evm.go | 16 +--- aggoracle/e2e_test.go | 48 +++++++++-- aggoracle/mock_ethtxmanager_test.go | 127 ++++++++++++++++++++++++++++ go.mod | 2 +- go.sum | 4 +- test/Makefile | 4 + 6 files changed, 177 insertions(+), 24 deletions(-) create mode 100644 aggoracle/mock_ethtxmanager_test.go diff --git a/aggoracle/chaingersender/evm.go b/aggoracle/chaingersender/evm.go index c7860528..3c9a8771 100644 --- a/aggoracle/chaingersender/evm.go +++ b/aggoracle/chaingersender/evm.go @@ -67,24 +67,16 @@ func (c *EVMChainGERSender) IsGERAlreadyInjected(ger common.Hash) (bool, error) if err != nil { return false, err } - return timestamp.Cmp(big.NewInt(0)) == 0, nil + return timestamp.Cmp(big.NewInt(0)) != 0, nil } func (c *EVMChainGERSender) UpdateGERWaitUntilMined(ctx context.Context, ger common.Hash) error { - opts := &bind.TransactOpts{ - From: c.sender, - // Hardcode dummy values to avoid calls to the client, - // ethtxmanager is going to handle that - NoSend: true, - Nonce: big.NewInt(1), - GasLimit: 1, - GasPrice: big.NewInt(1), - } - tx, err := c.gerContract.UpdateGlobalExitRoot(opts, ger) + abi, err := pessimisticglobalexitroot.PessimisticglobalexitrootMetaData.GetAbi() if err != nil { return err } - id, err := c.ethTxMan.Add(ctx, &c.gerAddr, nil, big.NewInt(0), tx.Data(), c.gasOffset, nil) + data, err := abi.Pack("updateGlobalExitRoot", ger) + id, err := c.ethTxMan.Add(ctx, &c.gerAddr, nil, big.NewInt(0), data, c.gasOffset, nil) if err != nil { return err } diff --git a/aggoracle/e2e_test.go b/aggoracle/e2e_test.go index dcda8662..b8b76f4b 100644 --- a/aggoracle/e2e_test.go +++ b/aggoracle/e2e_test.go @@ -7,18 +7,21 @@ import ( "testing" "time" - "github.com/0xPolygon/cdk-contracts-tooling/contracts/manual/globalexitrootnopush0" - "github.com/0xPolygon/cdk-contracts-tooling/contracts/manual/pessimisticglobalexitroot" + gerContractL1 "github.com/0xPolygon/cdk-contracts-tooling/contracts/manual/globalexitrootnopush0" + gerContractEVMChain "github.com/0xPolygon/cdk-contracts-tooling/contracts/manual/pessimisticglobalexitrootnopush0" "github.com/0xPolygon/cdk/aggoracle" "github.com/0xPolygon/cdk/aggoracle/chaingersender" "github.com/0xPolygon/cdk/etherman" "github.com/0xPolygon/cdk/l1infotreesync" + "github.com/0xPolygon/cdk/log" "github.com/0xPolygon/cdk/reorgdetector" + ethtxmanager "github.com/0xPolygonHermez/zkevm-ethtx-manager/ethtxmanager" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethclient/simulated" + mock "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -36,7 +39,7 @@ func TestEVM(t *testing.T) { func commonSetup(t *testing.T) ( *simulated.Backend, *l1infotreesync.L1InfoTreeSync, - *globalexitrootnopush0.Globalexitrootnopush0, + *gerContractL1.Globalexitrootnopush0, *bind.TransactOpts, ) { // Config and spin up @@ -68,7 +71,34 @@ func evmSetup(t *testing.T) aggoracle.ChainSender { require.NoError(t, err) l2Client, gerL2Addr, _, err := newSimulatedEVMAggSovereignChain(authL2) require.NoError(t, err) - sender, err := chaingersender.NewEVMChainGERSender(gerL2Addr, authL2.From, l2Client.Client(), nil, 0) + ethTxManMock := aggoracle.NewEthTxManagerMock(t) + // id, err := c.ethTxMan.Add(ctx, &c.gerAddr, nil, big.NewInt(0), tx.Data(), c.gasOffset, nil) + ethTxManMock.On("Add", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + Run(func(args mock.Arguments) { + ctx := context.Background() + nonce, err := l2Client.Client().PendingNonceAt(ctx, authL2.From) + if err != nil { + log.Error(err) + return + } + tx := types.NewTx(&types.LegacyTx{ + To: args.Get(1).(*common.Address), + Nonce: nonce, + Value: big.NewInt(0), + Data: args.Get(4).([]byte), + }) + signedTx, err := authL2.Signer(authL2.From, tx) + if err != nil { + log.Error(err) + return + } + l2Client.Client().SendTransaction(ctx, signedTx) + l2Client.Commit() + }). + Return(common.Hash{}, nil) + // res, err := c.ethTxMan.Result(ctx, id) + ethTxManMock.On("Add", mock.Anything, mock.Anything).Return(ethtxmanager.MonitoredTxStatusMined, nil) + sender, err := chaingersender.NewEVMChainGERSender(gerL2Addr, authL2.From, l2Client.Client(), ethTxManMock, 0) require.NoError(t, err) return sender @@ -77,7 +107,7 @@ func evmSetup(t *testing.T) aggoracle.ChainSender { func newSimulatedL1(auth *bind.TransactOpts) ( client *simulated.Backend, gerAddr common.Address, - gerContract *globalexitrootnopush0.Globalexitrootnopush0, + gerContract *gerContractL1.Globalexitrootnopush0, err error, ) { balance, _ := new(big.Int).SetString("10000000000000000000000000", 10) //nolint:gomnd @@ -90,7 +120,7 @@ func newSimulatedL1(auth *bind.TransactOpts) ( blockGasLimit := uint64(999999999999999999) //nolint:gomnd client = simulated.NewBackend(genesisAlloc, simulated.WithBlockGasLimit(blockGasLimit)) - gerAddr, _, gerContract, err = globalexitrootnopush0.DeployGlobalexitrootnopush0(auth, client.Client(), auth.From, auth.From) + gerAddr, _, gerContract, err = gerContractL1.DeployGlobalexitrootnopush0(auth, client.Client(), auth.From, auth.From) client.Commit() return @@ -99,7 +129,7 @@ func newSimulatedL1(auth *bind.TransactOpts) ( func newSimulatedEVMAggSovereignChain(auth *bind.TransactOpts) ( client *simulated.Backend, gerAddr common.Address, - gerContract *pessimisticglobalexitroot.Pessimisticglobalexitroot, + gerContract *gerContractEVMChain.Pessimisticglobalexitrootnopush0, err error, ) { balance, _ := new(big.Int).SetString("10000000000000000000000000", 10) //nolint:gomnd @@ -112,7 +142,7 @@ func newSimulatedEVMAggSovereignChain(auth *bind.TransactOpts) ( blockGasLimit := uint64(999999999999999999) //nolint:gomnd client = simulated.NewBackend(genesisAlloc, simulated.WithBlockGasLimit(blockGasLimit)) - gerAddr, _, gerContract, err = pessimisticglobalexitroot.DeployPessimisticglobalexitroot(auth, client.Client(), auth.From) + gerAddr, _, gerContract, err = gerContractEVMChain.DeployPessimisticglobalexitrootnopush0(auth, client.Client(), auth.From) client.Commit() return @@ -120,7 +150,7 @@ func newSimulatedEVMAggSovereignChain(auth *bind.TransactOpts) ( func runTest( t *testing.T, - gerL1Contract *globalexitrootnopush0.Globalexitrootnopush0, + gerL1Contract *gerContractL1.Globalexitrootnopush0, sender aggoracle.ChainSender, l1Client *simulated.Backend, authL1 *bind.TransactOpts, diff --git a/aggoracle/mock_ethtxmanager_test.go b/aggoracle/mock_ethtxmanager_test.go new file mode 100644 index 00000000..37bcbeda --- /dev/null +++ b/aggoracle/mock_ethtxmanager_test.go @@ -0,0 +1,127 @@ +// Code generated by mockery v2.22.1. DO NOT EDIT. + +package aggoracle + +import ( + big "math/big" + + common "github.com/ethereum/go-ethereum/common" + + context "context" + + ethtxmanager "github.com/0xPolygonHermez/zkevm-ethtx-manager/ethtxmanager" + + mock "github.com/stretchr/testify/mock" + + types "github.com/ethereum/go-ethereum/core/types" +) + +// EthTxManagerMock is an autogenerated mock type for the EthTxManager type +type EthTxManagerMock struct { + mock.Mock +} + +// Add provides a mock function with given fields: ctx, to, forcedNonce, value, data, gasOffset, sidecar +func (_m *EthTxManagerMock) Add(ctx context.Context, to *common.Address, forcedNonce *uint64, value *big.Int, data []byte, gasOffset uint64, sidecar *types.BlobTxSidecar) (common.Hash, error) { + ret := _m.Called(ctx, to, forcedNonce, value, data, gasOffset, sidecar) + + var r0 common.Hash + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *common.Address, *uint64, *big.Int, []byte, uint64, *types.BlobTxSidecar) (common.Hash, error)); ok { + return rf(ctx, to, forcedNonce, value, data, gasOffset, sidecar) + } + if rf, ok := ret.Get(0).(func(context.Context, *common.Address, *uint64, *big.Int, []byte, uint64, *types.BlobTxSidecar) common.Hash); ok { + r0 = rf(ctx, to, forcedNonce, value, data, gasOffset, sidecar) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(common.Hash) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *common.Address, *uint64, *big.Int, []byte, uint64, *types.BlobTxSidecar) error); ok { + r1 = rf(ctx, to, forcedNonce, value, data, gasOffset, sidecar) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Remove provides a mock function with given fields: ctx, id +func (_m *EthTxManagerMock) Remove(ctx context.Context, id common.Hash) error { + ret := _m.Called(ctx, id) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, common.Hash) error); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Result provides a mock function with given fields: ctx, id +func (_m *EthTxManagerMock) Result(ctx context.Context, id common.Hash) (ethtxmanager.MonitoredTxResult, error) { + ret := _m.Called(ctx, id) + + var r0 ethtxmanager.MonitoredTxResult + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, common.Hash) (ethtxmanager.MonitoredTxResult, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Hash) ethtxmanager.MonitoredTxResult); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Get(0).(ethtxmanager.MonitoredTxResult) + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Hash) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ResultsByStatus provides a mock function with given fields: ctx, statuses +func (_m *EthTxManagerMock) ResultsByStatus(ctx context.Context, statuses []ethtxmanager.MonitoredTxStatus) ([]ethtxmanager.MonitoredTxResult, error) { + ret := _m.Called(ctx, statuses) + + var r0 []ethtxmanager.MonitoredTxResult + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []ethtxmanager.MonitoredTxStatus) ([]ethtxmanager.MonitoredTxResult, error)); ok { + return rf(ctx, statuses) + } + if rf, ok := ret.Get(0).(func(context.Context, []ethtxmanager.MonitoredTxStatus) []ethtxmanager.MonitoredTxResult); ok { + r0 = rf(ctx, statuses) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]ethtxmanager.MonitoredTxResult) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []ethtxmanager.MonitoredTxStatus) error); ok { + r1 = rf(ctx, statuses) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +type mockConstructorTestingTNewEthTxManagerMock interface { + mock.TestingT + Cleanup(func()) +} + +// NewEthTxManagerMock creates a new instance of EthTxManagerMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewEthTxManagerMock(t mockConstructorTestingTNewEthTxManagerMock) *EthTxManagerMock { + mock := &EthTxManagerMock{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/go.mod b/go.mod index fdcf2398..ded6db29 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/0xPolygon/cdk go 1.22.4 require ( - github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240724124854-785bb2a0e4a2 + github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240726101945-d05a885ae884 github.com/0xPolygon/cdk-data-availability v0.0.8-0.20240712072318-72ae67613cbf github.com/0xPolygon/cdk-rpc v0.0.0-20240419104226-c0a62ba0f49d github.com/0xPolygonHermez/zkevm-data-streamer v0.2.3-RC4 diff --git a/go.sum b/go.sum index 96887d67..e5d5f8f9 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240724124854-785bb2a0e4a2 h1:vMRkvTf+sfCKtEDFRGlZ9saDzQIf+LR+ly2OiRyE/2Q= -github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240724124854-785bb2a0e4a2/go.mod h1:mFlcEjsm2YBBsu8atHJ3zyVnwM+Z/fMXpVmIJge+WVU= +github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240726101945-d05a885ae884 h1:oXUct6UWuGs15WyCEKipY0Kc0BsCnMzniAz0EIFoPxs= +github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240726101945-d05a885ae884/go.mod h1:mFlcEjsm2YBBsu8atHJ3zyVnwM+Z/fMXpVmIJge+WVU= github.com/0xPolygon/cdk-data-availability v0.0.8-0.20240712072318-72ae67613cbf h1:VWxVYeDhDURGp8pHR4kq3jwoXRazVHsQLMMIqYsO+Fw= github.com/0xPolygon/cdk-data-availability v0.0.8-0.20240712072318-72ae67613cbf/go.mod h1:3XkZ0zn0GsvAT01MPQMmukF534CVSFmtrcoK3F/BK6Q= github.com/0xPolygon/cdk-rpc v0.0.0-20240419104226-c0a62ba0f49d h1:sxh6hZ2jF/sxxj2jd5o1vuNNCZjYmn4aRG9SRlVaEFs= diff --git a/test/Makefile b/test/Makefile index 151f7336..07d49fd3 100644 --- a/test/Makefile +++ b/test/Makefile @@ -44,3 +44,7 @@ generate-mocks-l1infotreesync: ## Generates mocks for l1infotreesync , using moc export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=downloaderFull --dir=../l1infotreesync --output=../l1infotreesync --outpkg=l1infotreesync --inpackage --structname=DownloaderMock --filename=mock_downloader_test.go export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=processorInterface --dir=../l1infotreesync --output=../l1infotreesync --outpkg=l1infotreesync --inpackage --structname=ProcessorMock --filename=mock_processor_test.go export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=ReorgDetector --dir=../l1infotreesync --output=../l1infotreesync --outpkg=l1infotreesync --inpackage --structname=ReorgDetectorMock --filename=mock_reorgdetector_test.go + +.PHONY: generate-mocks-aggoracle +generate-mocks-aggoracle: ## Generates mocks for aggoracle , using mockery tool + export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=EthTxManager --dir=../aggoracle/chaingersender --output=../aggoracle --outpkg=aggoracle --structname=EthTxManagerMock --filename=mock_ethtxmanager_test.go From fd0eb733338f030d6c85187b96a95683535ea1cb Mon Sep 17 00:00:00 2001 From: Arnau Date: Thu, 25 Jul 2024 14:57:53 +0200 Subject: [PATCH 05/18] sync refactor --- aggoracle/chaingersender/evm.go | 33 +- aggoracle/e2e_test.go | 62 +- aggoracle/oracle.go | 5 +- l1infotreesync/downloader.go | 195 +---- l1infotreesync/driver.go | 143 ---- l1infotreesync/driver_test.go | 211 ------ l1infotreesync/e2e_test.go | 7 +- l1infotreesync/l1infotreesync.go | 72 +- l1infotreesync/processor.go | 16 +- l1infotreesync/processor_test.go | 680 +++++++++--------- localbridgesync/downloader.go | 211 ++---- localbridgesync/downloader_test.go | 467 ------------ localbridgesync/localbridgesync.go | 48 +- localbridgesync/mock_downloader_test.go | 100 --- localbridgesync/mock_l2_test.go | 484 ------------- localbridgesync/mock_processor_test.go | 81 --- localbridgesync/processor.go | 17 +- localbridgesync/processor_test.go | 153 ++-- localbridgesync/types.go | 42 -- sync/common.go | 21 + sync/evmdownloader.go | 198 +++++ .../evmdownloader_test.go | 178 +++-- .../driver.go => sync/evmdriver.go | 79 +- .../driver_test.go => sync/evmdriver_test.go | 82 ++- sync/evmtypes.go | 15 + .../mock_downloader_test.go | 41 +- {l1infotreesync => sync}/mock_l2_test.go | 2 +- .../mock_processor_test.go | 20 +- .../mock_reorgdetector_test.go | 2 +- test/Makefile | 22 +- 30 files changed, 1097 insertions(+), 2590 deletions(-) delete mode 100644 l1infotreesync/driver.go delete mode 100644 l1infotreesync/driver_test.go delete mode 100644 localbridgesync/downloader_test.go delete mode 100644 localbridgesync/mock_downloader_test.go delete mode 100644 localbridgesync/mock_l2_test.go delete mode 100644 localbridgesync/mock_processor_test.go delete mode 100644 localbridgesync/types.go create mode 100644 sync/common.go create mode 100644 sync/evmdownloader.go rename l1infotreesync/downloader_test.go => sync/evmdownloader_test.go (72%) rename localbridgesync/driver.go => sync/evmdriver.go (54%) rename localbridgesync/driver_test.go => sync/evmdriver_test.go (77%) create mode 100644 sync/evmtypes.go rename {l1infotreesync => sync}/mock_downloader_test.go (54%) rename {l1infotreesync => sync}/mock_l2_test.go (99%) rename {l1infotreesync => sync}/mock_processor_test.go (73%) rename {localbridgesync => sync}/mock_reorgdetector_test.go (98%) diff --git a/aggoracle/chaingersender/evm.go b/aggoracle/chaingersender/evm.go index 3c9a8771..b3b6e405 100644 --- a/aggoracle/chaingersender/evm.go +++ b/aggoracle/chaingersender/evm.go @@ -15,10 +15,6 @@ import ( "github.com/ethereum/go-ethereum/core/types" ) -var ( - waitPeriodMonitorTx = time.Second * 5 -) - type EthClienter interface { ethereum.LogFilterer ethereum.BlockNumberReader @@ -34,12 +30,13 @@ type EthTxManager interface { } type EVMChainGERSender struct { - gerContract *pessimisticglobalexitroot.Pessimisticglobalexitroot - gerAddr common.Address - sender common.Address - client EthClienter - ethTxMan EthTxManager - gasOffset uint64 + gerContract *pessimisticglobalexitroot.Pessimisticglobalexitroot + gerAddr common.Address + sender common.Address + client EthClienter + ethTxMan EthTxManager + gasOffset uint64 + waitPeriodMonitorTx time.Duration } func NewEVMChainGERSender( @@ -47,18 +44,20 @@ func NewEVMChainGERSender( client EthClienter, ethTxMan EthTxManager, gasOffset uint64, + waitPeriodMonitorTx time.Duration, ) (*EVMChainGERSender, error) { gerContract, err := pessimisticglobalexitroot.NewPessimisticglobalexitroot(globalExitRoot, client) if err != nil { return nil, err } return &EVMChainGERSender{ - gerContract: gerContract, - gerAddr: globalExitRoot, - sender: sender, - client: client, - ethTxMan: ethTxMan, - gasOffset: gasOffset, + gerContract: gerContract, + gerAddr: globalExitRoot, + sender: sender, + client: client, + ethTxMan: ethTxMan, + gasOffset: gasOffset, + waitPeriodMonitorTx: waitPeriodMonitorTx, }, nil } @@ -81,7 +80,7 @@ func (c *EVMChainGERSender) UpdateGERWaitUntilMined(ctx context.Context, ger com return err } for { - time.Sleep(waitPeriodMonitorTx) + time.Sleep(c.waitPeriodMonitorTx) res, err := c.ethTxMan.Result(ctx, id) if err != nil { log.Error("error calling ethTxMan.Result: ", err) diff --git a/aggoracle/e2e_test.go b/aggoracle/e2e_test.go index b8b76f4b..7d616be9 100644 --- a/aggoracle/e2e_test.go +++ b/aggoracle/e2e_test.go @@ -2,6 +2,7 @@ package aggoracle_test import ( "context" + "errors" "math/big" "strconv" "testing" @@ -16,6 +17,7 @@ import ( "github.com/0xPolygon/cdk/log" "github.com/0xPolygon/cdk/reorgdetector" ethtxmanager "github.com/0xPolygonHermez/zkevm-ethtx-manager/ethtxmanager" + "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" @@ -29,7 +31,7 @@ func TestEVM(t *testing.T) { ctx := context.Background() l1Client, syncer, gerL1Contract, authL1 := commonSetup(t) sender := evmSetup(t) - oracle, err := aggoracle.New(sender, l1Client.Client(), syncer, etherman.LatestBlock) + oracle, err := aggoracle.New(sender, l1Client.Client(), syncer, etherman.LatestBlock, time.Millisecond) require.NoError(t, err) go oracle.Start(ctx) @@ -57,9 +59,9 @@ func commonSetup(t *testing.T) ( require.NoError(t, err) // Syncer dbPathSyncer := t.TempDir() - syncer, err := l1infotreesync.New(ctx, dbPathSyncer, gerL1Addr, 10, etherman.LatestBlock, reorg, l1Client.Client(), 32) + syncer, err := l1infotreesync.New(ctx, dbPathSyncer, gerL1Addr, 10, etherman.LatestBlock, reorg, l1Client.Client(), 32, time.Millisecond) require.NoError(t, err) - go syncer.Sync(ctx) + go syncer.Start(ctx) return l1Client, syncer, gerL1Contract, authL1 } @@ -81,24 +83,56 @@ func evmSetup(t *testing.T) aggoracle.ChainSender { log.Error(err) return } - tx := types.NewTx(&types.LegacyTx{ + gas, err := l2Client.Client().EstimateGas(ctx, ethereum.CallMsg{ + From: authL2.From, To: args.Get(1).(*common.Address), - Nonce: nonce, Value: big.NewInt(0), Data: args.Get(4).([]byte), }) + if err != nil { + log.Error(err) + res, err := l2Client.Client().CallContract(ctx, ethereum.CallMsg{ + From: authL2.From, + To: args.Get(1).(*common.Address), + Value: big.NewInt(0), + Data: args.Get(4).([]byte), + }, nil) + log.Debugf("contract call: %s", res) + if err != nil { + log.Error(err) + } + return + } + price, err := l2Client.Client().SuggestGasPrice(ctx) + if err != nil { + log.Error(err) + } + tx := types.NewTx(&types.LegacyTx{ + To: args.Get(1).(*common.Address), + Nonce: nonce, + Value: big.NewInt(0), + Data: args.Get(4).([]byte), + Gas: gas, + GasPrice: price, + }) + tx.Gas() signedTx, err := authL2.Signer(authL2.From, tx) if err != nil { log.Error(err) return } - l2Client.Client().SendTransaction(ctx, signedTx) + err = l2Client.Client().SendTransaction(ctx, signedTx) + if err != nil { + log.Error(err) + return + } l2Client.Commit() }). Return(common.Hash{}, nil) // res, err := c.ethTxMan.Result(ctx, id) - ethTxManMock.On("Add", mock.Anything, mock.Anything).Return(ethtxmanager.MonitoredTxStatusMined, nil) - sender, err := chaingersender.NewEVMChainGERSender(gerL2Addr, authL2.From, l2Client.Client(), ethTxManMock, 0) + ethTxManMock.On("Result", mock.Anything, mock.Anything). + Return(ethtxmanager.MonitoredTxResult{Status: ethtxmanager.MonitoredTxStatusMined}, nil) + sender, err := chaingersender.NewEVMChainGERSender(gerL2Addr, authL2.From, l2Client.Client(), ethTxManMock, 0, time.Millisecond*50) require.NoError(t, err) return sender @@ -143,8 +177,18 @@ func newSimulatedEVMAggSovereignChain(auth *bind.TransactOpts) ( client = simulated.NewBackend(genesisAlloc, simulated.WithBlockGasLimit(blockGasLimit)) gerAddr, _, gerContract, err = gerContractEVMChain.DeployPessimisticglobalexitrootnopush0(auth, client.Client(), auth.From) + if err != nil { + return + } + client.Commit() + _GLOBAL_EXIT_ROOT_SETTER_ROLE := common.HexToHash("0x7b95520991dfda409891be0afa2635b63540f92ee996fda0bf695a166e5c5176") + _, err = gerContract.GrantRole(auth, _GLOBAL_EXIT_ROOT_SETTER_ROLE, auth.From) client.Commit() + hasRole, _ := gerContract.HasRole(&bind.CallOpts{Pending: false}, _GLOBAL_EXIT_ROOT_SETTER_ROLE, auth.From) + if !hasRole { + err = errors.New("failed to set role") + } return } @@ -159,7 +203,7 @@ func runTest( _, err := gerL1Contract.UpdateExitRoot(authL1, common.HexToHash(strconv.Itoa(i))) require.NoError(t, err) l1Client.Commit() - time.Sleep(time.Second * 30) + time.Sleep(time.Millisecond * 50) expectedGER, err := gerL1Contract.GetLastGlobalExitRoot(&bind.CallOpts{Pending: false}) require.NoError(t, err) isInjected, err := sender.IsGERAlreadyInjected(expectedGER) diff --git a/aggoracle/oracle.go b/aggoracle/oracle.go index f4957c7a..8f4b7a67 100644 --- a/aggoracle/oracle.go +++ b/aggoracle/oracle.go @@ -13,10 +13,6 @@ import ( "github.com/ethereum/go-ethereum/common" ) -var ( - waitPeriodNextGER = time.Second * 30 -) - type EthClienter interface { ethereum.LogFilterer ethereum.BlockNumberReader @@ -46,6 +42,7 @@ func New( l1Client EthClienter, l1InfoTreeSyncer L1InfoTreer, blockFinalityType etherman.BlockNumberFinality, + waitPeriodNextGER time.Duration, ) (*AggOracle, error) { ticker := time.NewTicker(waitPeriodNextGER) finality, err := blockFinalityType.ToBlockNum() diff --git a/l1infotreesync/downloader.go b/l1infotreesync/downloader.go index 549e482e..ba9b219b 100644 --- a/l1infotreesync/downloader.go +++ b/l1infotreesync/downloader.go @@ -1,13 +1,10 @@ package l1infotreesync import ( - "context" - "math/big" - "time" + "fmt" "github.com/0xPolygon/cdk-contracts-tooling/contracts/elderberry/polygonzkevmglobalexitrootv2" - "github.com/0xPolygon/cdk/etherman" - "github.com/0xPolygon/cdk/log" + "github.com/0xPolygon/cdk/sync" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" @@ -16,7 +13,6 @@ import ( ) var ( - waitForNewBlocksPeriod = time.Millisecond * 100 updateL1InfoTreeSignature = crypto.Keccak256Hash([]byte("UpdateL1InfoTree(bytes32,bytes32)")) ) @@ -27,172 +23,22 @@ type EthClienter interface { bind.ContractBackend } -type downloaderInterface interface { - waitForNewBlocks(ctx context.Context, lastBlockSeen uint64) (newLastBlock uint64) - getEventsByBlockRange(ctx context.Context, fromBlock, toBlock uint64) []block - getLogs(ctx context.Context, fromBlock, toBlock uint64) []types.Log - appendLog(b *block, l types.Log) - getBlockHeader(ctx context.Context, blockNum uint64) blockHeader -} - type L1InfoTreeUpdate struct { MainnetExitRoot common.Hash RollupExitRoot common.Hash } -type block struct { - blockHeader - Events []L1InfoTreeUpdate -} - -type blockHeader struct { - Num uint64 - Hash common.Hash - ParentHash common.Hash - Timestamp uint64 -} - -type downloader struct { - syncBlockChunkSize uint64 - downloaderInterface -} - -func newDownloader( - GERAddr common.Address, - ethClient EthClienter, - syncBlockChunkSize uint64, - blockFinalityType etherman.BlockNumberFinality, -) (*downloader, error) { - GERContract, err := polygonzkevmglobalexitrootv2.NewPolygonzkevmglobalexitrootv2(GERAddr, ethClient) - if err != nil { - return nil, err - } - finality, err := blockFinalityType.ToBlockNum() +func buildAppender(client EthClienter, globalExitRoot common.Address) (sync.LogAppenderMap, error) { + contract, err := polygonzkevmglobalexitrootv2.NewPolygonzkevmglobalexitrootv2(globalExitRoot, client) if err != nil { return nil, err } - return &downloader{ - syncBlockChunkSize: syncBlockChunkSize, - downloaderInterface: &downloaderImplementation{ - GERAddr: GERAddr, - GERContract: GERContract, - ethClient: ethClient, - blockFinality: finality, - }, - }, nil -} - -func (d *downloader) download(ctx context.Context, fromBlock uint64, downloadedCh chan block) { - lastBlock := d.waitForNewBlocks(ctx, 0) - for { - select { - case <-ctx.Done(): - log.Debug("closing channel") - close(downloadedCh) - return - default: - } - toBlock := fromBlock + d.syncBlockChunkSize - if toBlock > lastBlock { - toBlock = lastBlock - } - if fromBlock > toBlock { - log.Debug("waiting for new blocks, last block ", toBlock) - lastBlock = d.waitForNewBlocks(ctx, toBlock) - continue - } - log.Debugf("getting events from blocks %d to %d", fromBlock, toBlock) - blocks := d.getEventsByBlockRange(ctx, fromBlock, toBlock) - for _, b := range blocks { - log.Debugf("sending block %d to the driver (with events)", b.Num) - downloadedCh <- b - } - if len(blocks) == 0 || blocks[len(blocks)-1].Num < toBlock { - // Indicate the last downloaded block if there are not events on it - log.Debugf("sending block %d to the driver (without evvents)", toBlock) - downloadedCh <- block{ - blockHeader: d.getBlockHeader(ctx, toBlock), - } - } - fromBlock = toBlock + 1 - } -} - -type downloaderImplementation struct { - GERAddr common.Address - GERContract *polygonzkevmglobalexitrootv2.Polygonzkevmglobalexitrootv2 - ethClient EthClienter - blockFinality *big.Int -} - -func (d *downloaderImplementation) waitForNewBlocks(ctx context.Context, lastBlockSeen uint64) (newLastBlock uint64) { - attempts := 0 - for { - header, err := d.ethClient.HeaderByNumber(ctx, d.blockFinality) - if err != nil { - attempts++ - log.Error("error geting last block num from eth client: ", err) - retryHandler("waitForNewBlocks", attempts) - continue - } - if header.Number.Uint64() > lastBlockSeen { - return header.Number.Uint64() - } - time.Sleep(waitForNewBlocksPeriod) - } -} - -func (d *downloaderImplementation) getEventsByBlockRange(ctx context.Context, fromBlock, toBlock uint64) []block { - blocks := []block{} - logs := d.getLogs(ctx, fromBlock, toBlock) - for _, l := range logs { - if len(blocks) == 0 || blocks[len(blocks)-1].Num < l.BlockNumber { - b := d.getBlockHeader(ctx, l.BlockNumber) - blocks = append(blocks, block{ - blockHeader: blockHeader{ - Num: l.BlockNumber, - Hash: l.BlockHash, - Timestamp: b.Timestamp, - ParentHash: b.ParentHash, - }, - Events: []L1InfoTreeUpdate{}, - }) - } - d.appendLog(&blocks[len(blocks)-1], l) - } - - return blocks -} - -func (d *downloaderImplementation) getLogs(ctx context.Context, fromBlock, toBlock uint64) []types.Log { - query := ethereum.FilterQuery{ - FromBlock: new(big.Int).SetUint64(fromBlock), - Addresses: []common.Address{d.GERAddr}, - Topics: [][]common.Hash{ - {updateL1InfoTreeSignature}, - }, - ToBlock: new(big.Int).SetUint64(toBlock), - } - attempts := 0 - for { - logs, err := d.ethClient.FilterLogs(ctx, query) + appender := make(sync.LogAppenderMap) + appender[updateL1InfoTreeSignature] = func(b *sync.EVMBlock, l types.Log) error { + l1InfoTreeUpdate, err := contract.ParseUpdateL1InfoTree(l) if err != nil { - attempts++ - log.Error("error calling FilterLogs to eth client: ", err) - retryHandler("getLogs", attempts) - continue - } - return logs - } -} - -func (d *downloaderImplementation) appendLog(b *block, l types.Log) { - switch l.Topics[0] { - case updateL1InfoTreeSignature: - l1InfoTreeUpdate, err := d.GERContract.ParseUpdateL1InfoTree(l) - if err != nil { - log.Fatalf( - "error parsing log %+v using d.GERContract.ParseUpdateL1InfoTree: %v", + return fmt.Errorf( + "error parsing log %+v using contract.ParseUpdateL1InfoTree: %v", l, err, ) } @@ -200,26 +46,7 @@ func (d *downloaderImplementation) appendLog(b *block, l types.Log) { MainnetExitRoot: l1InfoTreeUpdate.MainnetExitRoot, RollupExitRoot: l1InfoTreeUpdate.RollupExitRoot, }) - default: - log.Fatalf("unexpected log %+v", l) - } -} - -func (d *downloaderImplementation) getBlockHeader(ctx context.Context, blockNum uint64) blockHeader { - attempts := 0 - for { - header, err := d.ethClient.HeaderByNumber(ctx, big.NewInt(int64(blockNum))) - if err != nil { - attempts++ - log.Errorf("error getting block header for block %d, err: %v", blockNum, err) - retryHandler("getBlockHeader", attempts) - continue - } - return blockHeader{ - Num: header.Number.Uint64(), - Hash: header.Hash(), - ParentHash: header.ParentHash, - Timestamp: header.Time, - } + return nil } + return appender, nil } diff --git a/l1infotreesync/driver.go b/l1infotreesync/driver.go deleted file mode 100644 index c907f681..00000000 --- a/l1infotreesync/driver.go +++ /dev/null @@ -1,143 +0,0 @@ -package l1infotreesync - -import ( - "context" - - "github.com/0xPolygon/cdk/log" - "github.com/0xPolygon/cdk/reorgdetector" - "github.com/ethereum/go-ethereum/common" -) - -const ( - downloadBufferSize = 1000 - reorgDetectorID = "localbridgesync" -) - -type downloaderFull interface { - downloaderInterface - download(ctx context.Context, fromBlock uint64, downloadedCh chan block) -} - -type driver struct { - reorgDetector ReorgDetector - reorgSub *reorgdetector.Subscription - processor processorInterface - downloader downloaderFull -} - -type processorInterface interface { - getLastProcessedBlock(ctx context.Context) (uint64, error) - processBlock(block block) error - reorg(firstReorgedBlock uint64) error -} - -type ReorgDetector interface { - Subscribe(id string) (*reorgdetector.Subscription, error) - AddBlockToTrack(ctx context.Context, id string, blockNum uint64, blockHash common.Hash) error -} - -func newDriver( - reorgDetector ReorgDetector, - processor processorInterface, - downloader downloaderFull, -) (*driver, error) { - reorgSub, err := reorgDetector.Subscribe(reorgDetectorID) - if err != nil { - return nil, err - } - return &driver{ - reorgDetector: reorgDetector, - reorgSub: reorgSub, - processor: processor, - downloader: downloader, - }, nil -} - -func (d *driver) Sync(ctx context.Context) { -reset: - var ( - lastProcessedBlock uint64 - attempts int - err error - ) - for { - lastProcessedBlock, err = d.processor.getLastProcessedBlock(ctx) - if err != nil { - attempts++ - log.Error("error geting last processed block: ", err) - retryHandler("Sync", attempts) - continue - } - break - } - cancellableCtx, cancel := context.WithCancel(ctx) - defer cancel() - - // start downloading - downloadCh := make(chan block, downloadBufferSize) - go d.downloader.download(cancellableCtx, lastProcessedBlock, downloadCh) - - for { - select { - case b := <-downloadCh: - log.Debug("handleNewBlock") - d.handleNewBlock(ctx, b) - case firstReorgedBlock := <-d.reorgSub.FirstReorgedBlock: - log.Debug("handleReorg") - d.handleReorg(cancel, downloadCh, firstReorgedBlock) - goto reset - } - } -} - -func (d *driver) handleNewBlock(ctx context.Context, b block) { - attempts := 0 - for { - err := d.reorgDetector.AddBlockToTrack(ctx, reorgDetectorID, b.Num, b.Hash) - if err != nil { - attempts++ - log.Errorf("error adding block %d to tracker: %v", b.Num, err) - retryHandler("handleNewBlock", attempts) - continue - } - break - } - attempts = 0 - for { - err := d.processor.processBlock(b) - if err != nil { - attempts++ - log.Errorf("error processing events for blcok %d, err: ", b.Num, err) - retryHandler("handleNewBlock", attempts) - continue - } - break - } -} - -func (d *driver) handleReorg( - cancel context.CancelFunc, downloadCh chan block, firstReorgedBlock uint64, -) { - // stop downloader - cancel() - _, ok := <-downloadCh - for ok { - _, ok = <-downloadCh - } - // handle reorg - attempts := 0 - for { - err := d.processor.reorg(firstReorgedBlock) - if err != nil { - attempts++ - log.Errorf( - "error processing reorg, last valid block %d, err: %v", - firstReorgedBlock, err, - ) - retryHandler("handleReorg", attempts) - continue - } - break - } - d.reorgSub.ReorgProcessed <- true -} diff --git a/l1infotreesync/driver_test.go b/l1infotreesync/driver_test.go deleted file mode 100644 index e206973a..00000000 --- a/l1infotreesync/driver_test.go +++ /dev/null @@ -1,211 +0,0 @@ -package l1infotreesync - -import ( - "context" - "errors" - "sync" - "testing" - "time" - - "github.com/0xPolygon/cdk/log" - "github.com/0xPolygon/cdk/reorgdetector" - "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" -) - -func TestSync(t *testing.T) { - retryAfterErrorPeriod = time.Millisecond * 100 - rdm := NewReorgDetectorMock(t) - pm := NewProcessorMock(t) - dm := NewDownloaderMock(t) - firstReorgedBlock := make(chan uint64) - reorgProcessed := make(chan bool) - rdm.On("Subscribe", reorgDetectorID).Return(&reorgdetector.Subscription{ - FirstReorgedBlock: firstReorgedBlock, - ReorgProcessed: reorgProcessed, - }) - driver, err := newDriver(rdm, pm, dm) - require.NoError(t, err) - ctx := context.Background() - expectedBlock1 := block{ - blockHeader: blockHeader{ - Num: 3, - Hash: common.HexToHash("03"), - }, - } - expectedBlock2 := block{ - blockHeader: blockHeader{ - Num: 9, - Hash: common.HexToHash("09"), - }, - } - type reorgSemaphore struct { - mu sync.Mutex - green bool - } - reorg1Completed := reorgSemaphore{} - dm.On("download", mock.Anything, mock.Anything, mock.Anything).Run(func(args mock.Arguments) { - ctx := args.Get(0).(context.Context) - downloadedCh := args.Get(2).(chan block) - log.Info("entering mock loop") - for { - select { - case <-ctx.Done(): - log.Info("closing channel") - close(downloadedCh) - return - default: - } - reorg1Completed.mu.Lock() - green := reorg1Completed.green - reorg1Completed.mu.Unlock() - if green { - downloadedCh <- expectedBlock2 - } else { - downloadedCh <- expectedBlock1 - } - time.Sleep(100 * time.Millisecond) - } - }) - - // Mocking this actions, the driver should "store" all the blocks from the downloader - pm.On("getLastProcessedBlock", ctx). - Return(uint64(3), nil) - rdm.On("AddBlockToTrack", ctx, reorgDetectorID, expectedBlock1.Num, expectedBlock1.Hash). - Return(nil) - pm.On("storeBridgeEvents", expectedBlock1.Num, expectedBlock1.Events). - Return(nil) - rdm.On("AddBlockToTrack", ctx, reorgDetectorID, expectedBlock2.Num, expectedBlock2.Hash). - Return(nil) - pm.On("storeBridgeEvents", expectedBlock2.Num, expectedBlock2.Events). - Return(nil) - go driver.Sync(ctx) - time.Sleep(time.Millisecond * 200) // time to download expectedBlock1 - - // Trigger reorg 1 - reorgedBlock1 := uint64(5) - pm.On("reorg", reorgedBlock1).Return(nil) - firstReorgedBlock <- reorgedBlock1 - ok := <-reorgProcessed - require.True(t, ok) - reorg1Completed.mu.Lock() - reorg1Completed.green = true - reorg1Completed.mu.Unlock() - time.Sleep(time.Millisecond * 200) // time to download expectedBlock2 - - // Trigger reorg 2: syncer restarts the porcess - reorgedBlock2 := uint64(7) - pm.On("reorg", reorgedBlock2).Return(nil) - firstReorgedBlock <- reorgedBlock2 - ok = <-reorgProcessed - require.True(t, ok) -} - -func TestHandleNewBlock(t *testing.T) { - retryAfterErrorPeriod = time.Millisecond * 100 - rdm := NewReorgDetectorMock(t) - pm := NewProcessorMock(t) - dm := NewDownloaderMock(t) - rdm.On("Subscribe", reorgDetectorID).Return(&reorgdetector.Subscription{}) - driver, err := newDriver(rdm, pm, dm) - require.NoError(t, err) - ctx := context.Background() - - // happy path - b1 := block{ - blockHeader: blockHeader{ - Num: 1, - Hash: common.HexToHash("f00"), - }, - } - rdm. - On("AddBlockToTrack", ctx, reorgDetectorID, b1.Num, b1.Hash). - Return(nil) - pm.On("storeBridgeEvents", b1.Num, b1.Events). - Return(nil) - driver.handleNewBlock(ctx, b1) - - // reorg deteector fails once - b2 := block{ - blockHeader: blockHeader{ - Num: 2, - Hash: common.HexToHash("f00"), - }, - } - rdm. - On("AddBlockToTrack", ctx, reorgDetectorID, b2.Num, b2.Hash). - Return(errors.New("foo")).Once() - rdm. - On("AddBlockToTrack", ctx, reorgDetectorID, b2.Num, b2.Hash). - Return(nil).Once() - pm.On("storeBridgeEvents", b2.Num, b2.Events). - Return(nil) - driver.handleNewBlock(ctx, b2) - - // processor fails once - b3 := block{ - blockHeader: blockHeader{ - Num: 3, - Hash: common.HexToHash("f00"), - }, - } - rdm. - On("AddBlockToTrack", ctx, reorgDetectorID, b3.Num, b3.Hash). - Return(nil) - pm.On("storeBridgeEvents", b3.Num, b3.Events). - Return(errors.New("foo")).Once() - pm.On("storeBridgeEvents", b3.Num, b3.Events). - Return(nil).Once() - driver.handleNewBlock(ctx, b3) - -} - -func TestHandleReorg(t *testing.T) { - retryAfterErrorPeriod = time.Millisecond * 100 - rdm := NewReorgDetectorMock(t) - pm := NewProcessorMock(t) - dm := NewDownloaderMock(t) - reorgProcessed := make(chan bool) - rdm.On("Subscribe", reorgDetectorID).Return(&reorgdetector.Subscription{ - ReorgProcessed: reorgProcessed, - }) - driver, err := newDriver(rdm, pm, dm) - require.NoError(t, err) - ctx := context.Background() - - // happy path - _, cancel := context.WithCancel(ctx) - downloadCh := make(chan block) - firstReorgedBlock := uint64(5) - pm.On("reorg", firstReorgedBlock).Return(nil) - go driver.handleReorg(cancel, downloadCh, firstReorgedBlock) - close(downloadCh) - done := <-reorgProcessed - require.True(t, done) - - // download ch sends some garbage - _, cancel = context.WithCancel(ctx) - downloadCh = make(chan block) - firstReorgedBlock = uint64(6) - pm.On("reorg", firstReorgedBlock).Return(nil) - go driver.handleReorg(cancel, downloadCh, firstReorgedBlock) - downloadCh <- block{} - downloadCh <- block{} - downloadCh <- block{} - close(downloadCh) - done = <-reorgProcessed - require.True(t, done) - - // processor fails 2 times - _, cancel = context.WithCancel(ctx) - downloadCh = make(chan block) - firstReorgedBlock = uint64(7) - pm.On("reorg", firstReorgedBlock).Return(errors.New("foo")).Once() - pm.On("reorg", firstReorgedBlock).Return(errors.New("foo")).Once() - pm.On("reorg", firstReorgedBlock).Return(nil).Once() - go driver.handleReorg(cancel, downloadCh, firstReorgedBlock) - close(downloadCh) - done = <-reorgProcessed - require.True(t, done) -} diff --git a/l1infotreesync/e2e_test.go b/l1infotreesync/e2e_test.go index baad1d53..dc5734d5 100644 --- a/l1infotreesync/e2e_test.go +++ b/l1infotreesync/e2e_test.go @@ -43,7 +43,6 @@ func newSimulatedClient(auth *bind.TransactOpts) ( } func TestE2E(t *testing.T) { - waitForNewBlocksPeriod = time.Millisecond ctx := context.Background() dbPath := t.TempDir() privateKey, err := crypto.GenerateKey() @@ -51,13 +50,13 @@ func TestE2E(t *testing.T) { auth, err := bind.NewKeyedTransactorWithChainID(privateKey, big.NewInt(1337)) require.NoError(t, err) rdm := NewReorgDetectorMock(t) - rdm.On("Subscribe", reorgDetectorID).Return(&reorgdetector.Subscription{}) + rdm.On("Subscribe", reorgDetectorID).Return(&reorgdetector.Subscription{}, nil) rdm.On("AddBlockToTrack", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) client, gerAddr, gerSc, err := newSimulatedClient(auth) require.NoError(t, err) - syncer, err := New(ctx, dbPath, gerAddr, 10, etherman.LatestBlock, rdm, client.Client(), 32) + syncer, err := New(ctx, dbPath, gerAddr, 10, etherman.LatestBlock, rdm, client.Client(), 32, time.Millisecond) require.NoError(t, err) - go syncer.Sync(ctx) + go syncer.Start(ctx) // Update GER 10 times // TODO: test syncer restart diff --git a/l1infotreesync/l1infotreesync.go b/l1infotreesync/l1infotreesync.go index fa04f0e6..847488df 100644 --- a/l1infotreesync/l1infotreesync.go +++ b/l1infotreesync/l1infotreesync.go @@ -5,18 +5,23 @@ import ( "time" "github.com/0xPolygon/cdk/etherman" - "github.com/0xPolygon/cdk/log" + "github.com/0xPolygon/cdk/sync" "github.com/ethereum/go-ethereum/common" ) +const ( + reorgDetectorID = "l1infotreesync" + downloadBufferSize = 1000 +) + var ( retryAfterErrorPeriod = time.Second * 10 maxRetryAttemptsAfterError = 5 ) type L1InfoTreeSync struct { - *processor - *driver + processor *processor + driver *sync.EVMDriver } func New( @@ -25,31 +30,66 @@ func New( globalExitRoot common.Address, syncBlockChunkSize uint64, blockFinalityType etherman.BlockNumberFinality, - rd ReorgDetector, + rd sync.ReorgDetector, l1Client EthClienter, treeHeight uint8, + waitForNewBlocksPeriod time.Duration, ) (*L1InfoTreeSync, error) { - p, err := newProcessor(ctx, dbPath, treeHeight) + processor, err := newProcessor(ctx, dbPath, treeHeight) if err != nil { return nil, err } - dwn, err := newDownloader(globalExitRoot, l1Client, syncBlockChunkSize, blockFinalityType) + + appender, err := buildAppender(l1Client, globalExitRoot) if err != nil { return nil, err } - dri, err := newDriver(rd, p, dwn) + downloader, err := sync.NewEVMDownloader( + l1Client, + syncBlockChunkSize, + blockFinalityType, + waitForNewBlocksPeriod, + appender, + []common.Address{globalExitRoot}, + ) if err != nil { return nil, err } - return &L1InfoTreeSync{p, dri}, nil -} -func retryHandler(funcName string, attempts int) { - if attempts >= maxRetryAttemptsAfterError { - log.Fatalf( - "%s failed too many times (%d)", - funcName, maxRetryAttemptsAfterError, - ) + driver, err := sync.NewEVMDriver(rd, processor, downloader, reorgDetectorID, downloadBufferSize) + if err != nil { + return nil, err } - time.Sleep(retryAfterErrorPeriod) + return &L1InfoTreeSync{ + processor: processor, + driver: driver, + }, nil +} + +func (s *L1InfoTreeSync) Start(ctx context.Context) { + s.driver.Sync(ctx) +} + +func (s *L1InfoTreeSync) ComputeMerkleProofByIndex(ctx context.Context, index uint32) ([][32]byte, common.Hash, error) { + return s.processor.ComputeMerkleProofByIndex(ctx, index) +} + +func (s *L1InfoTreeSync) ComputeMerkleProofByRoot(ctx context.Context, root common.Hash) ([][32]byte, common.Hash, error) { + return s.processor.ComputeMerkleProofByRoot(ctx, root) +} + +func (s *L1InfoTreeSync) GetInfoByRoot(ctx context.Context, root common.Hash) (*L1InfoTreeLeaf, error) { + return s.processor.GetInfoByRoot(ctx, root) +} + +func (s *L1InfoTreeSync) GetLatestInfoUntilBlock(ctx context.Context, blockNum uint64) (*L1InfoTreeLeaf, error) { + return s.processor.GetLatestInfoUntilBlock(ctx, blockNum) +} + +func (s *L1InfoTreeSync) GetInfoByIndex(ctx context.Context, index uint32) (*L1InfoTreeLeaf, error) { + return s.processor.GetInfoByIndex(ctx, index) +} + +func (s *L1InfoTreeSync) GetInfoByHash(ctx context.Context, hash []byte) (*L1InfoTreeLeaf, error) { + return s.processor.GetInfoByHash(ctx, hash) } diff --git a/l1infotreesync/processor.go b/l1infotreesync/processor.go index 12047d77..2247fae3 100644 --- a/l1infotreesync/processor.go +++ b/l1infotreesync/processor.go @@ -7,6 +7,7 @@ import ( "errors" "github.com/0xPolygon/cdk/l1infotree" + "github.com/0xPolygon/cdk/sync" "github.com/ethereum/go-ethereum/common" "github.com/ledgerwatch/erigon-lib/kv" "github.com/ledgerwatch/erigon-lib/kv/mdbx" @@ -268,7 +269,7 @@ func (p *processor) getInfoByHashWithTx(tx kv.Tx, hash []byte) (*L1InfoTreeLeaf, }, nil } -func (p *processor) getLastProcessedBlock(ctx context.Context) (uint64, error) { +func (p *processor) GetLastProcessedBlock(ctx context.Context) (uint64, error) { tx, err := p.db.BeginRo(ctx) if err != nil { return 0, err @@ -287,7 +288,7 @@ func (p *processor) getLastProcessedBlockWithTx(tx kv.Tx) (uint64, error) { } } -func (p *processor) reorg(firstReorgedBlock uint64) error { +func (p *processor) Reorg(firstReorgedBlock uint64) error { // TODO: Does tree need to be reorged? tx, err := p.db.BeginRw(context.Background()) if err != nil { @@ -362,9 +363,9 @@ func (p *processor) deleteLeaf(tx kv.RwTx, index uint32) error { return nil } -// processBlock process the leafs of the L1 info tree found on a block +// ProcessBlock process the leafs of the L1 info tree found on a block // this function can be called without leafs with the intention to track the last processed block -func (p *processor) processBlock(b block) error { +func (p *processor) ProcessBlock(b sync.EVMBlock) error { tx, err := p.db.BeginRw(context.Background()) if err != nil { return err @@ -380,11 +381,12 @@ func (p *processor) processBlock(b block) error { } else { initialIndex = lastIndex + 1 } - for i, l := range b.Events { + for i, e := range b.Events { + event := e.(L1InfoTreeUpdate) leafToStore := storeLeaf{ Index: initialIndex + uint32(i), - MainnetExitRoot: l.MainnetExitRoot, - RollupExitRoot: l.RollupExitRoot, + MainnetExitRoot: event.MainnetExitRoot, + RollupExitRoot: event.RollupExitRoot, ParentHash: b.ParentHash, Timestamp: b.Timestamp, BlockNumber: b.Num, diff --git a/l1infotreesync/processor_test.go b/l1infotreesync/processor_test.go index 949a3fde..b6f6c942 100644 --- a/l1infotreesync/processor_test.go +++ b/l1infotreesync/processor_test.go @@ -1,373 +1,363 @@ package l1infotreesync -import ( - "context" - "fmt" - "slices" - "testing" +// func TestProceessor(t *testing.T) { +// path := t.TempDir() +// ctx := context.Background() +// p, err := newProcessor(ctx, path, 32) +// require.NoError(t, err) +// actions := []processAction{ +// // processed: ~ +// &getLastProcessedBlockAction{ +// p: p, +// description: "on an empty processor", +// ctx: context.Background(), +// expectedLastProcessedBlock: 0, +// expectedErr: nil, +// }, +// &reorgAction{ +// p: p, +// description: "on an empty processor: firstReorgedBlock = 0", +// firstReorgedBlock: 0, +// expectedErr: nil, +// }, +// &reorgAction{ +// p: p, +// description: "on an empty processor: firstReorgedBlock = 1", +// firstReorgedBlock: 1, +// expectedErr: nil, +// }, +// &getClaimsAndBridgesAction{ +// p: p, +// description: "on an empty processor", +// ctx: context.Background(), +// fromBlock: 0, +// toBlock: 2, +// expectedEvents: nil, +// expectedErr: ErrBlockNotProcessed, +// }, +// &storeL1InfoTreeUpdatesAction{ +// p: p, +// description: "block1", +// b: block1, +// expectedErr: nil, +// }, +// // processed: block1 +// &getLastProcessedBlockAction{ +// p: p, +// description: "after block1", +// ctx: context.Background(), +// expectedLastProcessedBlock: 1, +// expectedErr: nil, +// }, +// &getClaimsAndBridgesAction{ +// p: p, +// description: "after block1: range 0, 2", +// ctx: context.Background(), +// fromBlock: 0, +// toBlock: 2, +// expectedEvents: nil, +// expectedErr: ErrBlockNotProcessed, +// }, +// &getClaimsAndBridgesAction{ +// p: p, +// description: "after block1: range 1, 1", +// ctx: context.Background(), +// fromBlock: 1, +// toBlock: 1, +// expectedEvents: block1.Events, +// expectedErr: nil, +// }, +// &reorgAction{ +// p: p, +// description: "after block1", +// firstReorgedBlock: 1, +// expectedErr: nil, +// }, +// // processed: ~ +// &getClaimsAndBridgesAction{ +// p: p, +// description: "after block1 reorged", +// ctx: context.Background(), +// fromBlock: 0, +// toBlock: 2, +// expectedEvents: nil, +// expectedErr: ErrBlockNotProcessed, +// }, +// &storeL1InfoTreeUpdatesAction{ +// p: p, +// description: "block1 (after it's reorged)", +// b: block1, +// expectedErr: nil, +// }, +// // processed: block3 +// &storeL1InfoTreeUpdatesAction{ +// p: p, +// description: "block3", +// b: block3, +// expectedErr: nil, +// }, +// // processed: block1, block3 +// &getLastProcessedBlockAction{ +// p: p, +// description: "after block3", +// ctx: context.Background(), +// expectedLastProcessedBlock: 3, +// expectedErr: nil, +// }, +// &getClaimsAndBridgesAction{ +// p: p, +// description: "after block3: range 2, 2", +// ctx: context.Background(), +// fromBlock: 2, +// toBlock: 2, +// expectedEvents: []L1InfoTreeUpdate{}, +// expectedErr: nil, +// }, +// &getClaimsAndBridgesAction{ +// p: p, +// description: "after block3: range 1, 3", +// ctx: context.Background(), +// fromBlock: 1, +// toBlock: 3, +// expectedEvents: append(block1.Events, block3.Events...), +// expectedErr: nil, +// }, +// &reorgAction{ +// p: p, +// description: "after block3, with value 3", +// firstReorgedBlock: 3, +// expectedErr: nil, +// }, +// // processed: block1 +// &getLastProcessedBlockAction{ +// p: p, +// description: "after block3 reorged", +// ctx: context.Background(), +// expectedLastProcessedBlock: 2, +// expectedErr: nil, +// }, +// &reorgAction{ +// p: p, +// description: "after block3, with value 2", +// firstReorgedBlock: 2, +// expectedErr: nil, +// }, +// &getLastProcessedBlockAction{ +// p: p, +// description: "after block2 reorged", +// ctx: context.Background(), +// expectedLastProcessedBlock: 1, +// expectedErr: nil, +// }, +// &storeL1InfoTreeUpdatesAction{ +// p: p, +// description: "block3 after reorg", +// b: block3, +// expectedErr: nil, +// }, +// // processed: block1, block3 +// &storeL1InfoTreeUpdatesAction{ +// p: p, +// description: "block4", +// b: block4, +// expectedErr: nil, +// }, +// // processed: block1, block3, block4 +// &storeL1InfoTreeUpdatesAction{ +// p: p, +// description: "block5", +// b: block5, +// expectedErr: nil, +// }, +// // processed: block1, block3, block4, block5 +// &getLastProcessedBlockAction{ +// p: p, +// description: "after block5", +// ctx: context.Background(), +// expectedLastProcessedBlock: 5, +// expectedErr: nil, +// }, +// &getClaimsAndBridgesAction{ +// p: p, +// description: "after block5: range 1, 3", +// ctx: context.Background(), +// fromBlock: 1, +// toBlock: 3, +// expectedEvents: append(block1.Events, block3.Events...), +// expectedErr: nil, +// }, +// &getClaimsAndBridgesAction{ +// p: p, +// description: "after block5: range 4, 5", +// ctx: context.Background(), +// fromBlock: 4, +// toBlock: 5, +// expectedEvents: append(block4.Events, block5.Events...), +// expectedErr: nil, +// }, +// &getClaimsAndBridgesAction{ +// p: p, +// description: "after block5: range 0, 5", +// ctx: context.Background(), +// fromBlock: 0, +// toBlock: 5, +// expectedEvents: slices.Concat( +// block1.Events, +// block3.Events, +// block4.Events, +// block5.Events, +// ), +// expectedErr: nil, +// }, +// } - "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/require" -) +// for _, a := range actions { +// t.Run(fmt.Sprintf("%s: %s", a.method(), a.desc()), a.execute) +// } +// } -func TestProceessor(t *testing.T) { - path := t.TempDir() - ctx := context.Background() - p, err := newProcessor(ctx, path, 32) - require.NoError(t, err) - actions := []processAction{ - // processed: ~ - &getLastProcessedBlockAction{ - p: p, - description: "on an empty processor", - ctx: context.Background(), - expectedLastProcessedBlock: 0, - expectedErr: nil, - }, - &reorgAction{ - p: p, - description: "on an empty processor: firstReorgedBlock = 0", - firstReorgedBlock: 0, - expectedErr: nil, - }, - &reorgAction{ - p: p, - description: "on an empty processor: firstReorgedBlock = 1", - firstReorgedBlock: 1, - expectedErr: nil, - }, - &getClaimsAndBridgesAction{ - p: p, - description: "on an empty processor", - ctx: context.Background(), - fromBlock: 0, - toBlock: 2, - expectedEvents: nil, - expectedErr: ErrBlockNotProcessed, - }, - &storeL1InfoTreeUpdatesAction{ - p: p, - description: "block1", - b: block1, - expectedErr: nil, - }, - // processed: block1 - &getLastProcessedBlockAction{ - p: p, - description: "after block1", - ctx: context.Background(), - expectedLastProcessedBlock: 1, - expectedErr: nil, - }, - &getClaimsAndBridgesAction{ - p: p, - description: "after block1: range 0, 2", - ctx: context.Background(), - fromBlock: 0, - toBlock: 2, - expectedEvents: nil, - expectedErr: ErrBlockNotProcessed, - }, - &getClaimsAndBridgesAction{ - p: p, - description: "after block1: range 1, 1", - ctx: context.Background(), - fromBlock: 1, - toBlock: 1, - expectedEvents: block1.Events, - expectedErr: nil, - }, - &reorgAction{ - p: p, - description: "after block1", - firstReorgedBlock: 1, - expectedErr: nil, - }, - // processed: ~ - &getClaimsAndBridgesAction{ - p: p, - description: "after block1 reorged", - ctx: context.Background(), - fromBlock: 0, - toBlock: 2, - expectedEvents: nil, - expectedErr: ErrBlockNotProcessed, - }, - &storeL1InfoTreeUpdatesAction{ - p: p, - description: "block1 (after it's reorged)", - b: block1, - expectedErr: nil, - }, - // processed: block3 - &storeL1InfoTreeUpdatesAction{ - p: p, - description: "block3", - b: block3, - expectedErr: nil, - }, - // processed: block1, block3 - &getLastProcessedBlockAction{ - p: p, - description: "after block3", - ctx: context.Background(), - expectedLastProcessedBlock: 3, - expectedErr: nil, - }, - &getClaimsAndBridgesAction{ - p: p, - description: "after block3: range 2, 2", - ctx: context.Background(), - fromBlock: 2, - toBlock: 2, - expectedEvents: []L1InfoTreeUpdate{}, - expectedErr: nil, - }, - &getClaimsAndBridgesAction{ - p: p, - description: "after block3: range 1, 3", - ctx: context.Background(), - fromBlock: 1, - toBlock: 3, - expectedEvents: append(block1.Events, block3.Events...), - expectedErr: nil, - }, - &reorgAction{ - p: p, - description: "after block3, with value 3", - firstReorgedBlock: 3, - expectedErr: nil, - }, - // processed: block1 - &getLastProcessedBlockAction{ - p: p, - description: "after block3 reorged", - ctx: context.Background(), - expectedLastProcessedBlock: 2, - expectedErr: nil, - }, - &reorgAction{ - p: p, - description: "after block3, with value 2", - firstReorgedBlock: 2, - expectedErr: nil, - }, - &getLastProcessedBlockAction{ - p: p, - description: "after block2 reorged", - ctx: context.Background(), - expectedLastProcessedBlock: 1, - expectedErr: nil, - }, - &storeL1InfoTreeUpdatesAction{ - p: p, - description: "block3 after reorg", - b: block3, - expectedErr: nil, - }, - // processed: block1, block3 - &storeL1InfoTreeUpdatesAction{ - p: p, - description: "block4", - b: block4, - expectedErr: nil, - }, - // processed: block1, block3, block4 - &storeL1InfoTreeUpdatesAction{ - p: p, - description: "block5", - b: block5, - expectedErr: nil, - }, - // processed: block1, block3, block4, block5 - &getLastProcessedBlockAction{ - p: p, - description: "after block5", - ctx: context.Background(), - expectedLastProcessedBlock: 5, - expectedErr: nil, - }, - &getClaimsAndBridgesAction{ - p: p, - description: "after block5: range 1, 3", - ctx: context.Background(), - fromBlock: 1, - toBlock: 3, - expectedEvents: append(block1.Events, block3.Events...), - expectedErr: nil, - }, - &getClaimsAndBridgesAction{ - p: p, - description: "after block5: range 4, 5", - ctx: context.Background(), - fromBlock: 4, - toBlock: 5, - expectedEvents: append(block4.Events, block5.Events...), - expectedErr: nil, - }, - &getClaimsAndBridgesAction{ - p: p, - description: "after block5: range 0, 5", - ctx: context.Background(), - fromBlock: 0, - toBlock: 5, - expectedEvents: slices.Concat( - block1.Events, - block3.Events, - block4.Events, - block5.Events, - ), - expectedErr: nil, - }, - } +// // BOILERPLATE - for _, a := range actions { - t.Run(fmt.Sprintf("%s: %s", a.method(), a.desc()), a.execute) - } -} +// // blocks -// BOILERPLATE +// var ( +// block1 = block{ +// blockHeader: blockHeader{ +// Num: 1, +// Hash: common.HexToHash("01"), +// }, +// Events: []L1InfoTreeUpdate{ +// {RollupExitRoot: common.HexToHash("01")}, +// {MainnetExitRoot: common.HexToHash("01")}, +// }, +// } +// block3 = block{ +// blockHeader: blockHeader{ +// Num: 3, +// Hash: common.HexToHash("02"), +// }, +// Events: []L1InfoTreeUpdate{ +// {RollupExitRoot: common.HexToHash("02"), MainnetExitRoot: common.HexToHash("02")}, +// }, +// } +// block4 = block{ +// blockHeader: blockHeader{ +// Num: 4, +// Hash: common.HexToHash("03"), +// }, +// Events: []L1InfoTreeUpdate{}, +// } +// block5 = block{ +// blockHeader: blockHeader{ +// Num: 5, +// Hash: common.HexToHash("04"), +// }, +// Events: []L1InfoTreeUpdate{ +// {RollupExitRoot: common.HexToHash("04")}, +// {MainnetExitRoot: common.HexToHash("05")}, +// }, +// } +// ) -// blocks +// // actions -var ( - block1 = block{ - blockHeader: blockHeader{ - Num: 1, - Hash: common.HexToHash("01"), - }, - Events: []L1InfoTreeUpdate{ - {RollupExitRoot: common.HexToHash("01")}, - {MainnetExitRoot: common.HexToHash("01")}, - }, - } - block3 = block{ - blockHeader: blockHeader{ - Num: 3, - Hash: common.HexToHash("02"), - }, - Events: []L1InfoTreeUpdate{ - {RollupExitRoot: common.HexToHash("02"), MainnetExitRoot: common.HexToHash("02")}, - }, - } - block4 = block{ - blockHeader: blockHeader{ - Num: 4, - Hash: common.HexToHash("03"), - }, - Events: []L1InfoTreeUpdate{}, - } - block5 = block{ - blockHeader: blockHeader{ - Num: 5, - Hash: common.HexToHash("04"), - }, - Events: []L1InfoTreeUpdate{ - {RollupExitRoot: common.HexToHash("04")}, - {MainnetExitRoot: common.HexToHash("05")}, - }, - } -) +// type processAction interface { +// method() string +// desc() string +// execute(t *testing.T) +// } -// actions +// // GetClaimsAndBridges -type processAction interface { - method() string - desc() string - execute(t *testing.T) -} +// type getClaimsAndBridgesAction struct { +// p *processor +// description string +// ctx context.Context +// fromBlock uint64 +// toBlock uint64 +// expectedEvents []L1InfoTreeUpdate +// expectedErr error +// } -// GetClaimsAndBridges +// func (a *getClaimsAndBridgesAction) method() string { +// return "GetClaimsAndBridges" +// } -type getClaimsAndBridgesAction struct { - p *processor - description string - ctx context.Context - fromBlock uint64 - toBlock uint64 - expectedEvents []L1InfoTreeUpdate - expectedErr error -} +// func (a *getClaimsAndBridgesAction) desc() string { +// return a.description +// } -func (a *getClaimsAndBridgesAction) method() string { - return "GetClaimsAndBridges" -} +// func (a *getClaimsAndBridgesAction) execute(t *testing.T) { +// // TODO: add relevant getters +// // actualEvents, actualErr := a.p.GetClaimsAndBridges(a.ctx, a.fromBlock, a.toBlock) +// // require.Equal(t, a.expectedEvents, actualEvents) +// // require.Equal(t, a.expectedErr, actualErr) +// } -func (a *getClaimsAndBridgesAction) desc() string { - return a.description -} +// // getLastProcessedBlock -func (a *getClaimsAndBridgesAction) execute(t *testing.T) { - // TODO: add relevant getters - // actualEvents, actualErr := a.p.GetClaimsAndBridges(a.ctx, a.fromBlock, a.toBlock) - // require.Equal(t, a.expectedEvents, actualEvents) - // require.Equal(t, a.expectedErr, actualErr) -} +// type getLastProcessedBlockAction struct { +// p *processor +// description string +// ctx context.Context +// expectedLastProcessedBlock uint64 +// expectedErr error +// } -// getLastProcessedBlock +// func (a *getLastProcessedBlockAction) method() string { +// return "getLastProcessedBlock" +// } -type getLastProcessedBlockAction struct { - p *processor - description string - ctx context.Context - expectedLastProcessedBlock uint64 - expectedErr error -} +// func (a *getLastProcessedBlockAction) desc() string { +// return a.description +// } -func (a *getLastProcessedBlockAction) method() string { - return "getLastProcessedBlock" -} +// func (a *getLastProcessedBlockAction) execute(t *testing.T) { +// actualLastProcessedBlock, actualErr := a.p.getLastProcessedBlock(a.ctx) +// require.Equal(t, a.expectedLastProcessedBlock, actualLastProcessedBlock) +// require.Equal(t, a.expectedErr, actualErr) +// } -func (a *getLastProcessedBlockAction) desc() string { - return a.description -} +// // reorg -func (a *getLastProcessedBlockAction) execute(t *testing.T) { - actualLastProcessedBlock, actualErr := a.p.getLastProcessedBlock(a.ctx) - require.Equal(t, a.expectedLastProcessedBlock, actualLastProcessedBlock) - require.Equal(t, a.expectedErr, actualErr) -} +// type reorgAction struct { +// p *processor +// description string +// firstReorgedBlock uint64 +// expectedErr error +// } -// reorg +// func (a *reorgAction) method() string { +// return "reorg" +// } -type reorgAction struct { - p *processor - description string - firstReorgedBlock uint64 - expectedErr error -} +// func (a *reorgAction) desc() string { +// return a.description +// } -func (a *reorgAction) method() string { - return "reorg" -} +// func (a *reorgAction) execute(t *testing.T) { +// actualErr := a.p.reorg(a.firstReorgedBlock) +// require.Equal(t, a.expectedErr, actualErr) +// } -func (a *reorgAction) desc() string { - return a.description -} +// // storeL1InfoTreeUpdates -func (a *reorgAction) execute(t *testing.T) { - actualErr := a.p.reorg(a.firstReorgedBlock) - require.Equal(t, a.expectedErr, actualErr) -} +// type storeL1InfoTreeUpdatesAction struct { +// p *processor +// description string +// b block +// expectedErr error +// } -// storeL1InfoTreeUpdates +// func (a *storeL1InfoTreeUpdatesAction) method() string { +// return "storeL1InfoTreeUpdates" +// } -type storeL1InfoTreeUpdatesAction struct { - p *processor - description string - b block - expectedErr error -} +// func (a *storeL1InfoTreeUpdatesAction) desc() string { +// return a.description +// } -func (a *storeL1InfoTreeUpdatesAction) method() string { - return "storeL1InfoTreeUpdates" -} - -func (a *storeL1InfoTreeUpdatesAction) desc() string { - return a.description -} - -func (a *storeL1InfoTreeUpdatesAction) execute(t *testing.T) { - actualErr := a.p.processBlock(a.b) - require.Equal(t, a.expectedErr, actualErr) -} +// func (a *storeL1InfoTreeUpdatesAction) execute(t *testing.T) { +// actualErr := a.p.processBlock(a.b) +// require.Equal(t, a.expectedErr, actualErr) +// } diff --git a/localbridgesync/downloader.go b/localbridgesync/downloader.go index 9763f818..955655f1 100644 --- a/localbridgesync/downloader.go +++ b/localbridgesync/downloader.go @@ -1,14 +1,13 @@ package localbridgesync import ( - "context" + "fmt" "math/big" "time" "github.com/0xPolygon/cdk-contracts-tooling/contracts/etrog/polygonzkevmbridge" "github.com/0xPolygon/cdk-contracts-tooling/contracts/etrog/polygonzkevmbridgev2" - "github.com/0xPolygon/cdk/etherman" - "github.com/0xPolygon/cdk/log" + "github.com/0xPolygon/cdk/sync" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" @@ -33,159 +32,45 @@ type EthClienter interface { bind.ContractBackend } -type downloaderInterface interface { - waitForNewBlocks(ctx context.Context, lastBlockSeen uint64) (newLastBlock uint64) - getEventsByBlockRange(ctx context.Context, fromBlock, toBlock uint64) []block - getLogs(ctx context.Context, fromBlock, toBlock uint64) []types.Log - appendLog(b *block, l types.Log) - getBlockHeader(ctx context.Context, blockNum uint64) blockHeader +type Bridge struct { + LeafType uint8 + OriginNetwork uint32 + OriginAddress common.Address + DestinationNetwork uint32 + DestinationAddress common.Address + Amount *big.Int + Metadata []byte + DepositCount uint32 } -type downloader struct { - syncBlockChunkSize uint64 - downloaderInterface +type Claim struct { + GlobalIndex *big.Int + OriginNetwork uint32 + OriginAddress common.Address + DestinationAddress common.Address + Amount *big.Int } -func newDownloader( - bridgeAddr common.Address, - ethClient EthClienter, - syncBlockChunkSize uint64, - blockFinalityType etherman.BlockNumberFinality, -) (*downloader, error) { - bridgeContractV1, err := polygonzkevmbridge.NewPolygonzkevmbridge(bridgeAddr, ethClient) - if err != nil { - return nil, err - } - bridgeContractV2, err := polygonzkevmbridgev2.NewPolygonzkevmbridgev2(bridgeAddr, ethClient) +type BridgeEvent struct { + Bridge *Bridge + Claim *Claim +} + +func buildAppender(client EthClienter, bridge common.Address) (sync.LogAppenderMap, error) { + bridgeContractV1, err := polygonzkevmbridge.NewPolygonzkevmbridge(bridge, client) if err != nil { return nil, err } - finality, err := blockFinalityType.ToBlockNum() + bridgeContractV2, err := polygonzkevmbridgev2.NewPolygonzkevmbridgev2(bridge, client) if err != nil { return nil, err } - return &downloader{ - syncBlockChunkSize: syncBlockChunkSize, - downloaderInterface: &downloaderImplementation{ - bridgeAddr: bridgeAddr, - bridgeContractV1: bridgeContractV1, - bridgeContractV2: bridgeContractV2, - ethClient: ethClient, - blockFinality: finality, - }, - }, nil -} - -func (d *downloader) download(ctx context.Context, fromBlock uint64, downloadedCh chan block) { - lastBlock := d.waitForNewBlocks(ctx, 0) - for { - select { - case <-ctx.Done(): - log.Debug("closing channel") - close(downloadedCh) - return - default: - } - toBlock := fromBlock + d.syncBlockChunkSize - if toBlock > lastBlock { - toBlock = lastBlock - } - if fromBlock > toBlock { - log.Debug("waiting for new blocks, last block ", toBlock) - lastBlock = d.waitForNewBlocks(ctx, toBlock) - continue - } - log.Debugf("getting events from blocks %d to %d", fromBlock, toBlock) - blocks := d.getEventsByBlockRange(ctx, fromBlock, toBlock) - for _, b := range blocks { - log.Debugf("sending block %d to the driver (with events)", b.Num) - downloadedCh <- b - } - if len(blocks) == 0 || blocks[len(blocks)-1].Num < toBlock { - // Indicate the last downloaded block if there are not events on it - log.Debugf("sending block %d to the driver (without evvents)", toBlock) - downloadedCh <- block{ - blockHeader: d.getBlockHeader(ctx, toBlock), - } - } - fromBlock = toBlock + 1 - } -} - -type downloaderImplementation struct { - bridgeAddr common.Address - bridgeContractV1 *polygonzkevmbridge.Polygonzkevmbridge - bridgeContractV2 *polygonzkevmbridgev2.Polygonzkevmbridgev2 - ethClient EthClienter - blockFinality *big.Int -} - -func (d *downloaderImplementation) waitForNewBlocks(ctx context.Context, lastBlockSeen uint64) (newLastBlock uint64) { - attempts := 0 - for { - header, err := d.ethClient.HeaderByNumber(ctx, d.blockFinality) - if err != nil { - attempts++ - log.Error("error geting last block num from eth client: ", err) - retryHandler("waitForNewBlocks", attempts) - continue - } - if header.Number.Uint64() > lastBlockSeen { - return header.Number.Uint64() - } - time.Sleep(waitForNewBlocksPeriod) - } -} - -func (d *downloaderImplementation) getEventsByBlockRange(ctx context.Context, fromBlock, toBlock uint64) []block { - blocks := []block{} - logs := d.getLogs(ctx, fromBlock, toBlock) - for _, l := range logs { - if len(blocks) == 0 || blocks[len(blocks)-1].Num < l.BlockNumber { - blocks = append(blocks, block{ - blockHeader: blockHeader{ - Num: l.BlockNumber, - Hash: l.BlockHash, - }, - Events: []BridgeEvent{}, - }) - } - d.appendLog(&blocks[len(blocks)-1], l) - } - - return blocks -} + appender := make(sync.LogAppenderMap) -func (d *downloaderImplementation) getLogs(ctx context.Context, fromBlock, toBlock uint64) []types.Log { - query := ethereum.FilterQuery{ - FromBlock: new(big.Int).SetUint64(fromBlock), - Addresses: []common.Address{d.bridgeAddr}, - Topics: [][]common.Hash{ - {bridgeEventSignature}, - {claimEventSignature}, - {claimEventSignaturePreEtrog}, - }, - ToBlock: new(big.Int).SetUint64(toBlock), - } - attempts := 0 - for { - logs, err := d.ethClient.FilterLogs(ctx, query) + appender[bridgeEventSignature] = func(b *sync.EVMBlock, l types.Log) error { + bridge, err := bridgeContractV2.ParseBridgeEvent(l) if err != nil { - attempts++ - log.Error("error calling FilterLogs to eth client: ", err) - retryHandler("getLogs", attempts) - continue - } - return logs - } -} - -func (d *downloaderImplementation) appendLog(b *block, l types.Log) { - switch l.Topics[0] { - case bridgeEventSignature: - bridge, err := d.bridgeContractV2.ParseBridgeEvent(l) - if err != nil { - log.Fatalf( + return fmt.Errorf( "error parsing log %+v using d.bridgeContractV2.ParseBridgeEvent: %v", l, err, ) @@ -200,10 +85,13 @@ func (d *downloaderImplementation) appendLog(b *block, l types.Log) { Metadata: bridge.Metadata, DepositCount: bridge.DepositCount, }}) - case claimEventSignature: - claim, err := d.bridgeContractV2.ParseClaimEvent(l) + return nil + } + + appender[claimEventSignature] = func(b *sync.EVMBlock, l types.Log) error { + claim, err := bridgeContractV2.ParseClaimEvent(l) if err != nil { - log.Fatalf( + return fmt.Errorf( "error parsing log %+v using d.bridgeContractV2.ParseClaimEvent: %v", l, err, ) @@ -215,10 +103,13 @@ func (d *downloaderImplementation) appendLog(b *block, l types.Log) { DestinationAddress: claim.DestinationAddress, Amount: claim.Amount, }}) - case claimEventSignaturePreEtrog: - claim, err := d.bridgeContractV1.ParseClaimEvent(l) + return nil + } + + appender[claimEventSignature] = func(b *sync.EVMBlock, l types.Log) error { + claim, err := bridgeContractV1.ParseClaimEvent(l) if err != nil { - log.Fatalf( + return fmt.Errorf( "error parsing log %+v using d.bridgeContractV1.ParseClaimEvent: %v", l, err, ) @@ -230,24 +121,8 @@ func (d *downloaderImplementation) appendLog(b *block, l types.Log) { DestinationAddress: claim.DestinationAddress, Amount: claim.Amount, }}) - default: - log.Fatalf("unexpected log %+v", l) + return nil } -} -func (d *downloaderImplementation) getBlockHeader(ctx context.Context, blockNum uint64) blockHeader { - attempts := 0 - for { - header, err := d.ethClient.HeaderByNumber(ctx, big.NewInt(int64(blockNum))) - if err != nil { - attempts++ - log.Errorf("error getting block header for block %d, err: %v", blockNum, err) - retryHandler("getBlockHeader", attempts) - continue - } - return blockHeader{ - Num: header.Number.Uint64(), - Hash: header.Hash(), - } - } + return appender, nil } diff --git a/localbridgesync/downloader_test.go b/localbridgesync/downloader_test.go deleted file mode 100644 index 553efbec..00000000 --- a/localbridgesync/downloader_test.go +++ /dev/null @@ -1,467 +0,0 @@ -package localbridgesync - -import ( - "context" - "errors" - "math/big" - "testing" - "time" - - "github.com/0xPolygon/cdk-contracts-tooling/contracts/etrog/polygonzkevmbridge" - "github.com/0xPolygon/cdk-contracts-tooling/contracts/etrog/polygonzkevmbridgev2" - cdkcommon "github.com/0xPolygon/cdk/common" - "github.com/0xPolygon/cdk/etherman" - "github.com/0xPolygon/cdk/log" - "github.com/ethereum/go-ethereum" - "github.com/ethereum/go-ethereum/accounts/abi" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" -) - -var ( - contractAddr = common.HexToAddress("1234567890") -) - -const ( - syncBlockChunck = uint64(10) -) - -func TestGetEventsByBlockRange(t *testing.T) { - type testCase struct { - description string - inputLogs []types.Log - fromBlock, toBlock uint64 - expectedBlocks []block - } - testCases := []testCase{} - clientMock := NewL2Mock(t) - ctx := context.Background() - d, err := newDownloader(contractAddr, clientMock, syncBlockChunck, etherman.LatestBlock) - require.NoError(t, err) - - // case 0: single block, no events - case0 := testCase{ - description: "case 0: single block, no events", - inputLogs: []types.Log{}, - fromBlock: 1, - toBlock: 3, - expectedBlocks: []block{}, - } - testCases = append(testCases, case0) - - // case 1: single block, single event - logC1, bridgeC1 := generateBridge(t, 3) - logsC1 := []types.Log{ - *logC1, - } - blocksC1 := []block{ - { - blockHeader: blockHeader{ - Num: logC1.BlockNumber, - Hash: logC1.BlockHash, - }, - Events: []BridgeEvent{ - { - Bridge: &bridgeC1, - }, - }, - }, - } - case1 := testCase{ - description: "case 1: single block, single event", - inputLogs: logsC1, - fromBlock: 3, - toBlock: 3, - expectedBlocks: blocksC1, - } - testCases = append(testCases, case1) - - // case 2: single block, multiple events - logC2_1, bridgeC2_1 := generateBridge(t, 5) - logC2_2, bridgeC2_2 := generateBridge(t, 5) - logC2_3, claimC2_1 := generateClaimV1(t, 5) - logC2_4, claimC2_2 := generateClaimV2(t, 5) - logsC2 := []types.Log{ - *logC2_1, - *logC2_2, - *logC2_3, - *logC2_4, - } - blocksC2 := []block{ - { - blockHeader: blockHeader{ - Num: logC2_1.BlockNumber, - Hash: logC2_1.BlockHash, - }, - Events: []BridgeEvent{ - {Bridge: &bridgeC2_1}, - {Bridge: &bridgeC2_2}, - {Claim: &claimC2_1}, - {Claim: &claimC2_2}, - }, - }, - } - case2 := testCase{ - description: "case 2: single block, multiple events", - inputLogs: logsC2, - fromBlock: 5, - toBlock: 5, - expectedBlocks: blocksC2, - } - testCases = append(testCases, case2) - - // case 3: multiple blocks, some events - logC3_1, bridgeC3_1 := generateBridge(t, 7) - logC3_2, bridgeC3_2 := generateBridge(t, 7) - logC3_3, claimC3_1 := generateClaimV1(t, 8) - logC3_4, claimC3_2 := generateClaimV2(t, 8) - logsC3 := []types.Log{ - *logC3_1, - *logC3_2, - *logC3_3, - *logC3_4, - } - blocksC3 := []block{ - { - blockHeader: blockHeader{ - Num: logC3_1.BlockNumber, - Hash: logC3_1.BlockHash, - }, - Events: []BridgeEvent{ - {Bridge: &bridgeC3_1}, - {Bridge: &bridgeC3_2}, - }, - }, - { - blockHeader: blockHeader{ - Num: logC3_3.BlockNumber, - Hash: logC3_3.BlockHash, - }, - Events: []BridgeEvent{ - {Claim: &claimC3_1}, - {Claim: &claimC3_2}, - }, - }, - } - case3 := testCase{ - description: "case 3: multiple blocks, some events", - inputLogs: logsC3, - fromBlock: 7, - toBlock: 8, - expectedBlocks: blocksC3, - } - testCases = append(testCases, case3) - - for _, tc := range testCases { - query := ethereum.FilterQuery{ - FromBlock: new(big.Int).SetUint64(tc.fromBlock), - Addresses: []common.Address{contractAddr}, - Topics: [][]common.Hash{ - {bridgeEventSignature}, - {claimEventSignature}, - {claimEventSignaturePreEtrog}, - }, - ToBlock: new(big.Int).SetUint64(tc.toBlock), - } - clientMock. - On("FilterLogs", mock.Anything, query). - Return(tc.inputLogs, nil) - - actualBlocks := d.getEventsByBlockRange(ctx, tc.fromBlock, tc.toBlock) - require.Equal(t, tc.expectedBlocks, actualBlocks, tc.description) - } -} - -func generateBridge(t *testing.T, blockNum uint32) (*types.Log, Bridge) { - b := Bridge{ - LeafType: 1, - OriginNetwork: blockNum, - OriginAddress: contractAddr, - DestinationNetwork: blockNum, - DestinationAddress: contractAddr, - Amount: big.NewInt(int64(blockNum)), - Metadata: common.Hex2Bytes("01"), - DepositCount: blockNum, - } - abi, err := polygonzkevmbridgev2.Polygonzkevmbridgev2MetaData.GetAbi() - require.NoError(t, err) - event, err := abi.EventByID(bridgeEventSignature) - require.NoError(t, err) - data, err := event.Inputs.Pack( - b.LeafType, - b.OriginNetwork, - b.OriginAddress, - b.DestinationNetwork, - b.DestinationAddress, - b.Amount, - b.Metadata, - b.DepositCount, - ) - require.NoError(t, err) - log := &types.Log{ - Address: contractAddr, - BlockNumber: uint64(blockNum), - BlockHash: common.BytesToHash(cdkcommon.BlockNum2Bytes(uint64(blockNum))), - Topics: []common.Hash{bridgeEventSignature}, - Data: data, - } - return log, b -} - -func generateClaimV1(t *testing.T, blockNum uint32) (*types.Log, Claim) { - abi, err := polygonzkevmbridge.PolygonzkevmbridgeMetaData.GetAbi() - require.NoError(t, err) - event, err := abi.EventByID(claimEventSignaturePreEtrog) - require.NoError(t, err) - return generateClaim(t, blockNum, event, true) -} - -func generateClaimV2(t *testing.T, blockNum uint32) (*types.Log, Claim) { - abi, err := polygonzkevmbridgev2.Polygonzkevmbridgev2MetaData.GetAbi() - require.NoError(t, err) - event, err := abi.EventByID(claimEventSignature) - require.NoError(t, err) - return generateClaim(t, blockNum, event, false) -} - -func generateClaim(t *testing.T, blockNum uint32, event *abi.Event, isV1 bool) (*types.Log, Claim) { - c := Claim{ - GlobalIndex: big.NewInt(int64(blockNum)), - OriginNetwork: blockNum, - OriginAddress: contractAddr, - DestinationAddress: contractAddr, - Amount: big.NewInt(int64(blockNum)), - } - var ( - data []byte - err error - signature common.Hash - ) - if isV1 { - data, err = event.Inputs.Pack( - uint32(c.GlobalIndex.Uint64()), - c.OriginNetwork, - c.OriginAddress, - c.DestinationAddress, - c.Amount, - ) - signature = claimEventSignaturePreEtrog - } else { - data, err = event.Inputs.Pack( - c.GlobalIndex, - c.OriginNetwork, - c.OriginAddress, - c.DestinationAddress, - c.Amount, - ) - signature = claimEventSignature - } - require.NoError(t, err) - log := &types.Log{ - Address: contractAddr, - BlockNumber: uint64(blockNum), - BlockHash: common.BytesToHash(cdkcommon.BlockNum2Bytes(uint64(blockNum))), - Topics: []common.Hash{signature}, - Data: data, - } - return log, c -} - -func TestDownload(t *testing.T) { - /* - NOTE: due to the concurrent nature of this test (the function being tested runs through a goroutine) - if the mock doesn't match, the goroutine will get stuck and the test will timeout - */ - d := NewDownloaderMock(t) - downloadCh := make(chan block, 1) - ctx := context.Background() - ctx1, cancel := context.WithCancel(ctx) - expectedBlocks := []block{} - clientMock := NewL2Mock(t) - dwnldr, err := newDownloader(contractAddr, clientMock, syncBlockChunck, etherman.LatestBlock) - require.NoError(t, err) - dwnldr.downloaderInterface = d - - d.On("waitForNewBlocks", mock.Anything, uint64(0)). - Return(uint64(1)) - // iteratiion 0: - // last block is 1, download that block (no events and wait) - b1 := block{ - blockHeader: blockHeader{ - Num: 1, - Hash: common.HexToHash("01"), - }, - } - expectedBlocks = append(expectedBlocks, b1) - d.On("getEventsByBlockRange", mock.Anything, uint64(0), uint64(1)). - Return([]block{}) - d.On("getBlockHeader", mock.Anything, uint64(1)). - Return(b1.blockHeader) - - // iteration 1: wait for next block to be created - d.On("waitForNewBlocks", mock.Anything, uint64(1)). - After(time.Millisecond * 100). - Return(uint64(2)).Once() - - // iteration 2: block 2 has events - b2 := block{ - blockHeader: blockHeader{ - Num: 2, - Hash: common.HexToHash("02"), - }, - } - expectedBlocks = append(expectedBlocks, b2) - d.On("getEventsByBlockRange", mock.Anything, uint64(2), uint64(2)). - Return([]block{b2}) - - // iteration 3: wait for next block to be created (jump to block 8) - d.On("waitForNewBlocks", mock.Anything, uint64(2)). - After(time.Millisecond * 100). - Return(uint64(8)).Once() - - // iteration 4: blocks 6 and 7 have events - b6 := block{ - blockHeader: blockHeader{ - Num: 6, - Hash: common.HexToHash("06"), - }, - Events: []BridgeEvent{ - {Claim: &Claim{OriginNetwork: 6}}, - }, - } - b7 := block{ - blockHeader: blockHeader{ - Num: 7, - Hash: common.HexToHash("07"), - }, - Events: []BridgeEvent{ - {Bridge: &Bridge{DestinationNetwork: 7}}, - }, - } - b8 := block{ - blockHeader: blockHeader{ - Num: 8, - Hash: common.HexToHash("08"), - }, - } - expectedBlocks = append(expectedBlocks, b6, b7, b8) - d.On("getEventsByBlockRange", mock.Anything, uint64(3), uint64(8)). - Return([]block{b6, b7}) - d.On("getBlockHeader", mock.Anything, uint64(8)). - Return(b8.blockHeader) - - // iteration 5: wait for next block to be created (jump to block 30) - d.On("waitForNewBlocks", mock.Anything, uint64(8)). - After(time.Millisecond * 100). - Return(uint64(30)).Once() - - // iteration 6: from block 9 to 19, no events - b19 := block{ - blockHeader: blockHeader{ - Num: 19, - Hash: common.HexToHash("19"), - }, - } - expectedBlocks = append(expectedBlocks, b19) - d.On("getEventsByBlockRange", mock.Anything, uint64(9), uint64(19)). - Return([]block{}) - d.On("getBlockHeader", mock.Anything, uint64(19)). - Return(b19.blockHeader) - - // iteration 7: from block 20 to 30, events on last block - b30 := block{ - blockHeader: blockHeader{ - Num: 30, - Hash: common.HexToHash("30"), - }, - Events: []BridgeEvent{ - {Bridge: &Bridge{DestinationNetwork: 30}}, - }, - } - expectedBlocks = append(expectedBlocks, b30) - d.On("getEventsByBlockRange", mock.Anything, uint64(20), uint64(30)). - Return([]block{b30}) - - // iteration 8: wait for next block to be created (jump to block 35) - d.On("waitForNewBlocks", mock.Anything, uint64(30)). - After(time.Millisecond * 100). - Return(uint64(35)).Once() - - go dwnldr.download(ctx1, 0, downloadCh) - for _, expectedBlock := range expectedBlocks { - actualBlock := <-downloadCh - log.Debugf("block %d received!", actualBlock.Num) - require.Equal(t, expectedBlock, actualBlock) - } - log.Debug("canceling") - cancel() - _, ok := <-downloadCh - require.False(t, ok) -} - -func TestWaitForNewBlocks(t *testing.T) { - retryAfterErrorPeriod = time.Millisecond * 100 - clientMock := NewL2Mock(t) - ctx := context.Background() - d, err := newDownloader(contractAddr, clientMock, syncBlockChunck, etherman.LatestBlock) - require.NoError(t, err) - - // at first attempt - currentBlock := uint64(5) - expectedBlock := uint64(6) - clientMock.On("HeaderByNumber", ctx, mock.Anything).Return(&types.Header{ - Number: big.NewInt(6), - }, nil).Once() - actualBlock := d.waitForNewBlocks(ctx, currentBlock) - assert.Equal(t, expectedBlock, actualBlock) - - // 2 iterations - clientMock.On("HeaderByNumber", ctx, mock.Anything).Return(&types.Header{ - Number: big.NewInt(5), - }, nil).Once() - clientMock.On("HeaderByNumber", ctx, mock.Anything).Return(&types.Header{ - Number: big.NewInt(6), - }, nil).Once() - actualBlock = d.waitForNewBlocks(ctx, currentBlock) - assert.Equal(t, expectedBlock, actualBlock) - - // after error from client - clientMock.On("HeaderByNumber", ctx, mock.Anything).Return(nil, errors.New("foo")).Once() - clientMock.On("HeaderByNumber", ctx, mock.Anything).Return(&types.Header{ - Number: big.NewInt(6), - }, nil).Once() - actualBlock = d.waitForNewBlocks(ctx, currentBlock) - assert.Equal(t, expectedBlock, actualBlock) -} - -func TestGetBlockHeader(t *testing.T) { - retryAfterErrorPeriod = time.Millisecond * 100 - clientMock := NewL2Mock(t) - ctx := context.Background() - d, err := newDownloader(contractAddr, clientMock, syncBlockChunck, etherman.LatestBlock) - require.NoError(t, err) - - blockNum := uint64(5) - blockNumBig := big.NewInt(5) - returnedBlock := &types.Header{ - Number: blockNumBig, - } - expectedBlock := blockHeader{ - Num: 5, - Hash: returnedBlock.Hash(), - } - - // at first attempt - clientMock.On("HeaderByNumber", ctx, blockNumBig).Return(returnedBlock, nil).Once() - actualBlock := d.getBlockHeader(ctx, blockNum) - assert.Equal(t, expectedBlock, actualBlock) - - // after error from client - clientMock.On("HeaderByNumber", ctx, blockNumBig).Return(nil, errors.New("foo")).Once() - clientMock.On("HeaderByNumber", ctx, blockNumBig).Return(returnedBlock, nil).Once() - actualBlock = d.getBlockHeader(ctx, blockNum) - assert.Equal(t, expectedBlock, actualBlock) -} diff --git a/localbridgesync/localbridgesync.go b/localbridgesync/localbridgesync.go index 42ab67d1..6707bbad 100644 --- a/localbridgesync/localbridgesync.go +++ b/localbridgesync/localbridgesync.go @@ -1,21 +1,27 @@ package localbridgesync import ( + "context" "time" "github.com/0xPolygon/cdk/etherman" - "github.com/0xPolygon/cdk/log" + "github.com/0xPolygon/cdk/sync" "github.com/ethereum/go-ethereum/common" ) +const ( + reorgDetectorID = "localbridgesync" + downloadBufferSize = 1000 +) + var ( retryAfterErrorPeriod = time.Second * 10 maxRetryAttemptsAfterError = 5 ) type LocalBridgeSync struct { - *processor - *driver + processor *processor + driver *sync.EVMDriver } func New( @@ -23,30 +29,40 @@ func New( bridge common.Address, syncBlockChunkSize uint64, blockFinalityType etherman.BlockNumberFinality, - rd ReorgDetector, + rd sync.ReorgDetector, l2Client EthClienter, ) (*LocalBridgeSync, error) { - p, err := newProcessor(dbPath) + processor, err := newProcessor(dbPath) if err != nil { return nil, err } - dwn, err := newDownloader(bridge, l2Client, syncBlockChunkSize, blockFinalityType) + + appender, err := buildAppender(l2Client, bridge) if err != nil { return nil, err } - dri, err := newDriver(rd, p, dwn) + downloader, err := sync.NewEVMDownloader( + l2Client, + syncBlockChunkSize, + blockFinalityType, + waitForNewBlocksPeriod, + appender, + []common.Address{bridge}, + ) if err != nil { return nil, err } - return &LocalBridgeSync{p, dri}, nil -} -func retryHandler(funcName string, attempts int) { - if attempts >= maxRetryAttemptsAfterError { - log.Fatalf( - "%s failed too many times (%d)", - funcName, maxRetryAttemptsAfterError, - ) + driver, err := sync.NewEVMDriver(rd, processor, downloader, reorgDetectorID, downloadBufferSize) + if err != nil { + return nil, err } - time.Sleep(retryAfterErrorPeriod) + return &LocalBridgeSync{ + processor: processor, + driver: driver, + }, nil +} + +func (s *LocalBridgeSync) Start(ctx context.Context) { + s.driver.Sync(ctx) } diff --git a/localbridgesync/mock_downloader_test.go b/localbridgesync/mock_downloader_test.go deleted file mode 100644 index f2df97d0..00000000 --- a/localbridgesync/mock_downloader_test.go +++ /dev/null @@ -1,100 +0,0 @@ -// Code generated by mockery v2.22.1. DO NOT EDIT. - -package localbridgesync - -import ( - context "context" - - types "github.com/ethereum/go-ethereum/core/types" - mock "github.com/stretchr/testify/mock" -) - -// DownloaderMock is an autogenerated mock type for the downloaderFull type -type DownloaderMock struct { - mock.Mock -} - -// appendLog provides a mock function with given fields: b, l -func (_m *DownloaderMock) appendLog(b *block, l types.Log) { - _m.Called(b, l) -} - -// download provides a mock function with given fields: ctx, fromBlock, downloadedCh -func (_m *DownloaderMock) download(ctx context.Context, fromBlock uint64, downloadedCh chan block) { - _m.Called(ctx, fromBlock, downloadedCh) -} - -// getBlockHeader provides a mock function with given fields: ctx, blockNum -func (_m *DownloaderMock) getBlockHeader(ctx context.Context, blockNum uint64) blockHeader { - ret := _m.Called(ctx, blockNum) - - var r0 blockHeader - if rf, ok := ret.Get(0).(func(context.Context, uint64) blockHeader); ok { - r0 = rf(ctx, blockNum) - } else { - r0 = ret.Get(0).(blockHeader) - } - - return r0 -} - -// getEventsByBlockRange provides a mock function with given fields: ctx, fromBlock, toBlock -func (_m *DownloaderMock) getEventsByBlockRange(ctx context.Context, fromBlock uint64, toBlock uint64) []block { - ret := _m.Called(ctx, fromBlock, toBlock) - - var r0 []block - if rf, ok := ret.Get(0).(func(context.Context, uint64, uint64) []block); ok { - r0 = rf(ctx, fromBlock, toBlock) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]block) - } - } - - return r0 -} - -// getLogs provides a mock function with given fields: ctx, fromBlock, toBlock -func (_m *DownloaderMock) getLogs(ctx context.Context, fromBlock uint64, toBlock uint64) []types.Log { - ret := _m.Called(ctx, fromBlock, toBlock) - - var r0 []types.Log - if rf, ok := ret.Get(0).(func(context.Context, uint64, uint64) []types.Log); ok { - r0 = rf(ctx, fromBlock, toBlock) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]types.Log) - } - } - - return r0 -} - -// waitForNewBlocks provides a mock function with given fields: ctx, lastBlockSeen -func (_m *DownloaderMock) waitForNewBlocks(ctx context.Context, lastBlockSeen uint64) uint64 { - ret := _m.Called(ctx, lastBlockSeen) - - var r0 uint64 - if rf, ok := ret.Get(0).(func(context.Context, uint64) uint64); ok { - r0 = rf(ctx, lastBlockSeen) - } else { - r0 = ret.Get(0).(uint64) - } - - return r0 -} - -type mockConstructorTestingTNewDownloaderMock interface { - mock.TestingT - Cleanup(func()) -} - -// NewDownloaderMock creates a new instance of DownloaderMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewDownloaderMock(t mockConstructorTestingTNewDownloaderMock) *DownloaderMock { - mock := &DownloaderMock{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/localbridgesync/mock_l2_test.go b/localbridgesync/mock_l2_test.go deleted file mode 100644 index 78baa614..00000000 --- a/localbridgesync/mock_l2_test.go +++ /dev/null @@ -1,484 +0,0 @@ -// Code generated by mockery v2.22.1. DO NOT EDIT. - -package localbridgesync - -import ( - context "context" - big "math/big" - - common "github.com/ethereum/go-ethereum/common" - - ethereum "github.com/ethereum/go-ethereum" - - mock "github.com/stretchr/testify/mock" - - types "github.com/ethereum/go-ethereum/core/types" -) - -// L2Mock is an autogenerated mock type for the EthClienter type -type L2Mock struct { - mock.Mock -} - -// BlockByHash provides a mock function with given fields: ctx, hash -func (_m *L2Mock) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) { - ret := _m.Called(ctx, hash) - - var r0 *types.Block - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, common.Hash) (*types.Block, error)); ok { - return rf(ctx, hash) - } - if rf, ok := ret.Get(0).(func(context.Context, common.Hash) *types.Block); ok { - r0 = rf(ctx, hash) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*types.Block) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, common.Hash) error); ok { - r1 = rf(ctx, hash) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// BlockByNumber provides a mock function with given fields: ctx, number -func (_m *L2Mock) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) { - ret := _m.Called(ctx, number) - - var r0 *types.Block - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *big.Int) (*types.Block, error)); ok { - return rf(ctx, number) - } - if rf, ok := ret.Get(0).(func(context.Context, *big.Int) *types.Block); ok { - r0 = rf(ctx, number) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*types.Block) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, *big.Int) error); ok { - r1 = rf(ctx, number) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// BlockNumber provides a mock function with given fields: ctx -func (_m *L2Mock) BlockNumber(ctx context.Context) (uint64, error) { - ret := _m.Called(ctx) - - var r0 uint64 - var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (uint64, error)); ok { - return rf(ctx) - } - if rf, ok := ret.Get(0).(func(context.Context) uint64); ok { - r0 = rf(ctx) - } else { - r0 = ret.Get(0).(uint64) - } - - if rf, ok := ret.Get(1).(func(context.Context) error); ok { - r1 = rf(ctx) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// CallContract provides a mock function with given fields: ctx, call, blockNumber -func (_m *L2Mock) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) { - ret := _m.Called(ctx, call, blockNumber) - - var r0 []byte - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, ethereum.CallMsg, *big.Int) ([]byte, error)); ok { - return rf(ctx, call, blockNumber) - } - if rf, ok := ret.Get(0).(func(context.Context, ethereum.CallMsg, *big.Int) []byte); ok { - r0 = rf(ctx, call, blockNumber) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]byte) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, ethereum.CallMsg, *big.Int) error); ok { - r1 = rf(ctx, call, blockNumber) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// CodeAt provides a mock function with given fields: ctx, contract, blockNumber -func (_m *L2Mock) CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error) { - ret := _m.Called(ctx, contract, blockNumber) - - var r0 []byte - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, common.Address, *big.Int) ([]byte, error)); ok { - return rf(ctx, contract, blockNumber) - } - if rf, ok := ret.Get(0).(func(context.Context, common.Address, *big.Int) []byte); ok { - r0 = rf(ctx, contract, blockNumber) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]byte) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, common.Address, *big.Int) error); ok { - r1 = rf(ctx, contract, blockNumber) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// EstimateGas provides a mock function with given fields: ctx, call -func (_m *L2Mock) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error) { - ret := _m.Called(ctx, call) - - var r0 uint64 - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, ethereum.CallMsg) (uint64, error)); ok { - return rf(ctx, call) - } - if rf, ok := ret.Get(0).(func(context.Context, ethereum.CallMsg) uint64); ok { - r0 = rf(ctx, call) - } else { - r0 = ret.Get(0).(uint64) - } - - if rf, ok := ret.Get(1).(func(context.Context, ethereum.CallMsg) error); ok { - r1 = rf(ctx, call) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// FilterLogs provides a mock function with given fields: ctx, q -func (_m *L2Mock) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error) { - ret := _m.Called(ctx, q) - - var r0 []types.Log - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, ethereum.FilterQuery) ([]types.Log, error)); ok { - return rf(ctx, q) - } - if rf, ok := ret.Get(0).(func(context.Context, ethereum.FilterQuery) []types.Log); ok { - r0 = rf(ctx, q) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]types.Log) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, ethereum.FilterQuery) error); ok { - r1 = rf(ctx, q) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// HeaderByHash provides a mock function with given fields: ctx, hash -func (_m *L2Mock) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) { - ret := _m.Called(ctx, hash) - - var r0 *types.Header - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, common.Hash) (*types.Header, error)); ok { - return rf(ctx, hash) - } - if rf, ok := ret.Get(0).(func(context.Context, common.Hash) *types.Header); ok { - r0 = rf(ctx, hash) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*types.Header) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, common.Hash) error); ok { - r1 = rf(ctx, hash) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// HeaderByNumber provides a mock function with given fields: ctx, number -func (_m *L2Mock) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) { - ret := _m.Called(ctx, number) - - var r0 *types.Header - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *big.Int) (*types.Header, error)); ok { - return rf(ctx, number) - } - if rf, ok := ret.Get(0).(func(context.Context, *big.Int) *types.Header); ok { - r0 = rf(ctx, number) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*types.Header) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, *big.Int) error); ok { - r1 = rf(ctx, number) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// PendingCodeAt provides a mock function with given fields: ctx, account -func (_m *L2Mock) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) { - ret := _m.Called(ctx, account) - - var r0 []byte - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, common.Address) ([]byte, error)); ok { - return rf(ctx, account) - } - if rf, ok := ret.Get(0).(func(context.Context, common.Address) []byte); ok { - r0 = rf(ctx, account) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]byte) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, common.Address) error); ok { - r1 = rf(ctx, account) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// PendingNonceAt provides a mock function with given fields: ctx, account -func (_m *L2Mock) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) { - ret := _m.Called(ctx, account) - - var r0 uint64 - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, common.Address) (uint64, error)); ok { - return rf(ctx, account) - } - if rf, ok := ret.Get(0).(func(context.Context, common.Address) uint64); ok { - r0 = rf(ctx, account) - } else { - r0 = ret.Get(0).(uint64) - } - - if rf, ok := ret.Get(1).(func(context.Context, common.Address) error); ok { - r1 = rf(ctx, account) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// SendTransaction provides a mock function with given fields: ctx, tx -func (_m *L2Mock) SendTransaction(ctx context.Context, tx *types.Transaction) error { - ret := _m.Called(ctx, tx) - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *types.Transaction) error); ok { - r0 = rf(ctx, tx) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// SubscribeFilterLogs provides a mock function with given fields: ctx, q, ch -func (_m *L2Mock) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) { - ret := _m.Called(ctx, q, ch) - - var r0 ethereum.Subscription - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, ethereum.FilterQuery, chan<- types.Log) (ethereum.Subscription, error)); ok { - return rf(ctx, q, ch) - } - if rf, ok := ret.Get(0).(func(context.Context, ethereum.FilterQuery, chan<- types.Log) ethereum.Subscription); ok { - r0 = rf(ctx, q, ch) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(ethereum.Subscription) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, ethereum.FilterQuery, chan<- types.Log) error); ok { - r1 = rf(ctx, q, ch) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// SubscribeNewHead provides a mock function with given fields: ctx, ch -func (_m *L2Mock) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error) { - ret := _m.Called(ctx, ch) - - var r0 ethereum.Subscription - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, chan<- *types.Header) (ethereum.Subscription, error)); ok { - return rf(ctx, ch) - } - if rf, ok := ret.Get(0).(func(context.Context, chan<- *types.Header) ethereum.Subscription); ok { - r0 = rf(ctx, ch) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(ethereum.Subscription) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, chan<- *types.Header) error); ok { - r1 = rf(ctx, ch) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// SuggestGasPrice provides a mock function with given fields: ctx -func (_m *L2Mock) SuggestGasPrice(ctx context.Context) (*big.Int, error) { - ret := _m.Called(ctx) - - var r0 *big.Int - var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (*big.Int, error)); ok { - return rf(ctx) - } - if rf, ok := ret.Get(0).(func(context.Context) *big.Int); ok { - r0 = rf(ctx) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*big.Int) - } - } - - if rf, ok := ret.Get(1).(func(context.Context) error); ok { - r1 = rf(ctx) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// SuggestGasTipCap provides a mock function with given fields: ctx -func (_m *L2Mock) SuggestGasTipCap(ctx context.Context) (*big.Int, error) { - ret := _m.Called(ctx) - - var r0 *big.Int - var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (*big.Int, error)); ok { - return rf(ctx) - } - if rf, ok := ret.Get(0).(func(context.Context) *big.Int); ok { - r0 = rf(ctx) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*big.Int) - } - } - - if rf, ok := ret.Get(1).(func(context.Context) error); ok { - r1 = rf(ctx) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// TransactionCount provides a mock function with given fields: ctx, blockHash -func (_m *L2Mock) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error) { - ret := _m.Called(ctx, blockHash) - - var r0 uint - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, common.Hash) (uint, error)); ok { - return rf(ctx, blockHash) - } - if rf, ok := ret.Get(0).(func(context.Context, common.Hash) uint); ok { - r0 = rf(ctx, blockHash) - } else { - r0 = ret.Get(0).(uint) - } - - if rf, ok := ret.Get(1).(func(context.Context, common.Hash) error); ok { - r1 = rf(ctx, blockHash) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// TransactionInBlock provides a mock function with given fields: ctx, blockHash, index -func (_m *L2Mock) TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error) { - ret := _m.Called(ctx, blockHash, index) - - var r0 *types.Transaction - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, common.Hash, uint) (*types.Transaction, error)); ok { - return rf(ctx, blockHash, index) - } - if rf, ok := ret.Get(0).(func(context.Context, common.Hash, uint) *types.Transaction); ok { - r0 = rf(ctx, blockHash, index) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*types.Transaction) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, common.Hash, uint) error); ok { - r1 = rf(ctx, blockHash, index) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -type mockConstructorTestingTNewL2Mock interface { - mock.TestingT - Cleanup(func()) -} - -// NewL2Mock creates a new instance of L2Mock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewL2Mock(t mockConstructorTestingTNewL2Mock) *L2Mock { - mock := &L2Mock{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/localbridgesync/mock_processor_test.go b/localbridgesync/mock_processor_test.go deleted file mode 100644 index 4a629f5c..00000000 --- a/localbridgesync/mock_processor_test.go +++ /dev/null @@ -1,81 +0,0 @@ -// Code generated by mockery v2.22.1. DO NOT EDIT. - -package localbridgesync - -import ( - context "context" - - mock "github.com/stretchr/testify/mock" -) - -// ProcessorMock is an autogenerated mock type for the processorInterface type -type ProcessorMock struct { - mock.Mock -} - -// getLastProcessedBlock provides a mock function with given fields: ctx -func (_m *ProcessorMock) getLastProcessedBlock(ctx context.Context) (uint64, error) { - ret := _m.Called(ctx) - - var r0 uint64 - var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (uint64, error)); ok { - return rf(ctx) - } - if rf, ok := ret.Get(0).(func(context.Context) uint64); ok { - r0 = rf(ctx) - } else { - r0 = ret.Get(0).(uint64) - } - - if rf, ok := ret.Get(1).(func(context.Context) error); ok { - r1 = rf(ctx) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// reorg provides a mock function with given fields: firstReorgedBlock -func (_m *ProcessorMock) reorg(firstReorgedBlock uint64) error { - ret := _m.Called(firstReorgedBlock) - - var r0 error - if rf, ok := ret.Get(0).(func(uint64) error); ok { - r0 = rf(firstReorgedBlock) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// storeBridgeEvents provides a mock function with given fields: blockNum, events -func (_m *ProcessorMock) storeBridgeEvents(blockNum uint64, events []BridgeEvent) error { - ret := _m.Called(blockNum, events) - - var r0 error - if rf, ok := ret.Get(0).(func(uint64, []BridgeEvent) error); ok { - r0 = rf(blockNum, events) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -type mockConstructorTestingTNewProcessorMock interface { - mock.TestingT - Cleanup(func()) -} - -// NewProcessorMock creates a new instance of ProcessorMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewProcessorMock(t mockConstructorTestingTNewProcessorMock) *ProcessorMock { - mock := &ProcessorMock{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/localbridgesync/processor.go b/localbridgesync/processor.go index 69c885b8..443a7925 100644 --- a/localbridgesync/processor.go +++ b/localbridgesync/processor.go @@ -6,6 +6,7 @@ import ( "errors" "github.com/0xPolygon/cdk/common" + "github.com/0xPolygon/cdk/sync" "github.com/ledgerwatch/erigon-lib/kv" "github.com/ledgerwatch/erigon-lib/kv/mdbx" ) @@ -87,7 +88,7 @@ func (p *processor) GetClaimsAndBridges( return events, nil } -func (p *processor) getLastProcessedBlock(ctx context.Context) (uint64, error) { +func (p *processor) GetLastProcessedBlock(ctx context.Context) (uint64, error) { tx, err := p.db.BeginRo(ctx) if err != nil { return 0, err @@ -106,7 +107,7 @@ func (p *processor) getLastProcessedBlockWithTx(tx kv.Tx) (uint64, error) { } } -func (p *processor) reorg(firstReorgedBlock uint64) error { +func (p *processor) Reorg(firstReorgedBlock uint64) error { tx, err := p.db.BeginRw(context.Background()) if err != nil { return err @@ -134,23 +135,27 @@ func (p *processor) reorg(firstReorgedBlock uint64) error { return tx.Commit() } -func (p *processor) storeBridgeEvents(blockNum uint64, events []BridgeEvent) error { +func (p *processor) ProcessBlock(block sync.EVMBlock) error { tx, err := p.db.BeginRw(context.Background()) if err != nil { return err } - if len(events) > 0 { + if len(block.Events) > 0 { + events := []BridgeEvent{} + for _, e := range block.Events { + events = append(events, e.(BridgeEvent)) + } value, err := json.Marshal(events) if err != nil { tx.Rollback() return err } - if err := tx.Put(eventsTable, common.BlockNum2Bytes(blockNum), value); err != nil { + if err := tx.Put(eventsTable, common.BlockNum2Bytes(block.Num), value); err != nil { tx.Rollback() return err } } - if err := p.updateLastProcessedBlock(tx, blockNum); err != nil { + if err := p.updateLastProcessedBlock(tx, block.Num); err != nil { tx.Rollback() return err } diff --git a/localbridgesync/processor_test.go b/localbridgesync/processor_test.go index 8e6884c2..a7835256 100644 --- a/localbridgesync/processor_test.go +++ b/localbridgesync/processor_test.go @@ -7,6 +7,7 @@ import ( "slices" "testing" + "github.com/0xPolygon/cdk/sync" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" ) @@ -45,11 +46,10 @@ func TestProceessor(t *testing.T) { expectedEvents: nil, expectedErr: ErrBlockNotProcessed, }, - &storeBridgeEventsAction{ + &processBlockAction{ p: p, description: "block1", - blockNum: block1.Num, - events: block1.Events, + block: block1, expectedErr: nil, }, // processed: block1 @@ -75,7 +75,7 @@ func TestProceessor(t *testing.T) { ctx: context.Background(), fromBlock: 1, toBlock: 1, - expectedEvents: block1.Events, + expectedEvents: eventsToBridgeEvents(block1.Events), expectedErr: nil, }, &reorgAction{ @@ -94,19 +94,17 @@ func TestProceessor(t *testing.T) { expectedEvents: nil, expectedErr: ErrBlockNotProcessed, }, - &storeBridgeEventsAction{ + &processBlockAction{ p: p, description: "block1 (after it's reorged)", - blockNum: block1.Num, - events: block1.Events, + block: block1, expectedErr: nil, }, // processed: block3 - &storeBridgeEventsAction{ + &processBlockAction{ p: p, description: "block3", - blockNum: block3.Num, - events: block3.Events, + block: block3, expectedErr: nil, }, // processed: block1, block3 @@ -127,13 +125,16 @@ func TestProceessor(t *testing.T) { expectedErr: nil, }, &getClaimsAndBridgesAction{ - p: p, - description: "after block3: range 1, 3", - ctx: context.Background(), - fromBlock: 1, - toBlock: 3, - expectedEvents: append(block1.Events, block3.Events...), - expectedErr: nil, + p: p, + description: "after block3: range 1, 3", + ctx: context.Background(), + fromBlock: 1, + toBlock: 3, + expectedEvents: append( + eventsToBridgeEvents(block1.Events), + eventsToBridgeEvents(block3.Events)..., + ), + expectedErr: nil, }, &reorgAction{ p: p, @@ -162,27 +163,24 @@ func TestProceessor(t *testing.T) { expectedLastProcessedBlock: 1, expectedErr: nil, }, - &storeBridgeEventsAction{ + &processBlockAction{ p: p, description: "block3 after reorg", - blockNum: block3.Num, - events: block3.Events, + block: block3, expectedErr: nil, }, // processed: block1, block3 - &storeBridgeEventsAction{ + &processBlockAction{ p: p, description: "block4", - blockNum: block4.Num, - events: block4.Events, + block: block4, expectedErr: nil, }, // processed: block1, block3, block4 - &storeBridgeEventsAction{ + &processBlockAction{ p: p, description: "block5", - blockNum: block5.Num, - events: block5.Events, + block: block5, expectedErr: nil, }, // processed: block1, block3, block4, block5 @@ -194,22 +192,28 @@ func TestProceessor(t *testing.T) { expectedErr: nil, }, &getClaimsAndBridgesAction{ - p: p, - description: "after block5: range 1, 3", - ctx: context.Background(), - fromBlock: 1, - toBlock: 3, - expectedEvents: append(block1.Events, block3.Events...), - expectedErr: nil, + p: p, + description: "after block5: range 1, 3", + ctx: context.Background(), + fromBlock: 1, + toBlock: 3, + expectedEvents: append( + eventsToBridgeEvents(block1.Events), + eventsToBridgeEvents(block3.Events)..., + ), + expectedErr: nil, }, &getClaimsAndBridgesAction{ - p: p, - description: "after block5: range 4, 5", - ctx: context.Background(), - fromBlock: 4, - toBlock: 5, - expectedEvents: append(block4.Events, block5.Events...), - expectedErr: nil, + p: p, + description: "after block5: range 4, 5", + ctx: context.Background(), + fromBlock: 4, + toBlock: 5, + expectedEvents: append( + eventsToBridgeEvents(block4.Events), + eventsToBridgeEvents(block5.Events)..., + ), + expectedErr: nil, }, &getClaimsAndBridgesAction{ p: p, @@ -218,10 +222,10 @@ func TestProceessor(t *testing.T) { fromBlock: 0, toBlock: 5, expectedEvents: slices.Concat( - block1.Events, - block3.Events, - block4.Events, - block5.Events, + eventsToBridgeEvents(block1.Events), + eventsToBridgeEvents(block3.Events), + eventsToBridgeEvents(block4.Events), + eventsToBridgeEvents(block5.Events), ), expectedErr: nil, }, @@ -237,13 +241,13 @@ func TestProceessor(t *testing.T) { // blocks var ( - block1 = block{ - blockHeader: blockHeader{ + block1 = sync.EVMBlock{ + EVMBlockHeader: sync.EVMBlockHeader{ Num: 1, Hash: common.HexToHash("01"), }, - Events: []BridgeEvent{ - {Bridge: &Bridge{ + Events: []interface{}{ + BridgeEvent{Bridge: &Bridge{ LeafType: 1, OriginNetwork: 1, OriginAddress: common.HexToAddress("01"), @@ -253,7 +257,7 @@ var ( Metadata: common.Hex2Bytes("01"), DepositCount: 1, }}, - {Claim: &Claim{ + BridgeEvent{Claim: &Claim{ GlobalIndex: big.NewInt(1), OriginNetwork: 1, OriginAddress: common.HexToAddress("01"), @@ -262,13 +266,13 @@ var ( }}, }, } - block3 = block{ - blockHeader: blockHeader{ + block3 = sync.EVMBlock{ + EVMBlockHeader: sync.EVMBlockHeader{ Num: 3, Hash: common.HexToHash("02"), }, - Events: []BridgeEvent{ - {Bridge: &Bridge{ + Events: []interface{}{ + BridgeEvent{Bridge: &Bridge{ LeafType: 2, OriginNetwork: 2, OriginAddress: common.HexToAddress("02"), @@ -278,7 +282,7 @@ var ( Metadata: common.Hex2Bytes("02"), DepositCount: 2, }}, - {Bridge: &Bridge{ + BridgeEvent{Bridge: &Bridge{ LeafType: 3, OriginNetwork: 3, OriginAddress: common.HexToAddress("03"), @@ -290,27 +294,27 @@ var ( }}, }, } - block4 = block{ - blockHeader: blockHeader{ + block4 = sync.EVMBlock{ + EVMBlockHeader: sync.EVMBlockHeader{ Num: 4, Hash: common.HexToHash("03"), }, - Events: []BridgeEvent{}, + Events: []interface{}{}, } - block5 = block{ - blockHeader: blockHeader{ + block5 = sync.EVMBlock{ + EVMBlockHeader: sync.EVMBlockHeader{ Num: 5, Hash: common.HexToHash("04"), }, - Events: []BridgeEvent{ - {Claim: &Claim{ + Events: []interface{}{ + BridgeEvent{Claim: &Claim{ GlobalIndex: big.NewInt(4), OriginNetwork: 4, OriginAddress: common.HexToAddress("04"), DestinationAddress: common.HexToAddress("04"), Amount: big.NewInt(4), }}, - {Claim: &Claim{ + BridgeEvent{Claim: &Claim{ GlobalIndex: big.NewInt(5), OriginNetwork: 5, OriginAddress: common.HexToAddress("05"), @@ -374,7 +378,7 @@ func (a *getLastProcessedBlockAction) desc() string { } func (a *getLastProcessedBlockAction) execute(t *testing.T) { - actualLastProcessedBlock, actualErr := a.p.getLastProcessedBlock(a.ctx) + actualLastProcessedBlock, actualErr := a.p.GetLastProcessedBlock(a.ctx) require.Equal(t, a.expectedLastProcessedBlock, actualLastProcessedBlock) require.Equal(t, a.expectedErr, actualErr) } @@ -397,29 +401,36 @@ func (a *reorgAction) desc() string { } func (a *reorgAction) execute(t *testing.T) { - actualErr := a.p.reorg(a.firstReorgedBlock) + actualErr := a.p.Reorg(a.firstReorgedBlock) require.Equal(t, a.expectedErr, actualErr) } // storeBridgeEvents -type storeBridgeEventsAction struct { +type processBlockAction struct { p *processor description string - blockNum uint64 - events []BridgeEvent + block sync.EVMBlock expectedErr error } -func (a *storeBridgeEventsAction) method() string { +func (a *processBlockAction) method() string { return "storeBridgeEvents" } -func (a *storeBridgeEventsAction) desc() string { +func (a *processBlockAction) desc() string { return a.description } -func (a *storeBridgeEventsAction) execute(t *testing.T) { - actualErr := a.p.storeBridgeEvents(a.blockNum, a.events) +func (a *processBlockAction) execute(t *testing.T) { + actualErr := a.p.ProcessBlock(a.block) require.Equal(t, a.expectedErr, actualErr) } + +func eventsToBridgeEvents(events []interface{}) []BridgeEvent { + bridgeEvents := []BridgeEvent{} + for _, event := range events { + bridgeEvents = append(bridgeEvents, event.(BridgeEvent)) + } + return bridgeEvents +} diff --git a/localbridgesync/types.go b/localbridgesync/types.go deleted file mode 100644 index 3a6a508e..00000000 --- a/localbridgesync/types.go +++ /dev/null @@ -1,42 +0,0 @@ -package localbridgesync - -import ( - "math/big" - - "github.com/ethereum/go-ethereum/common" -) - -type Bridge struct { - LeafType uint8 - OriginNetwork uint32 - OriginAddress common.Address - DestinationNetwork uint32 - DestinationAddress common.Address - Amount *big.Int - Metadata []byte - DepositCount uint32 -} - -type Claim struct { - // TODO: pre uLxLy there was Index instead of GlobalIndex, should we treat this differently? - GlobalIndex *big.Int - OriginNetwork uint32 - OriginAddress common.Address - DestinationAddress common.Address - Amount *big.Int -} - -type BridgeEvent struct { - Bridge *Bridge - Claim *Claim -} - -type block struct { - blockHeader - Events []BridgeEvent -} - -type blockHeader struct { - Num uint64 - Hash common.Hash -} diff --git a/sync/common.go b/sync/common.go new file mode 100644 index 00000000..6d1011f5 --- /dev/null +++ b/sync/common.go @@ -0,0 +1,21 @@ +package sync + +import ( + "log" + "time" +) + +var ( + RetryAfterErrorPeriod = time.Second * 10 + MaxRetryAttemptsAfterError = 5 +) + +func RetryHandler(funcName string, attempts int) { + if attempts >= MaxRetryAttemptsAfterError { + log.Fatalf( + "%s failed too many times (%d)", + funcName, MaxRetryAttemptsAfterError, + ) + } + time.Sleep(RetryAfterErrorPeriod) +} diff --git a/sync/evmdownloader.go b/sync/evmdownloader.go new file mode 100644 index 00000000..e6d9dc8d --- /dev/null +++ b/sync/evmdownloader.go @@ -0,0 +1,198 @@ +package sync + +import ( + "context" + "math/big" + "time" + + "github.com/0xPolygon/cdk/etherman" + "github.com/0xPolygon/cdk/log" + "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" +) + +type EthClienter interface { + ethereum.LogFilterer + ethereum.BlockNumberReader + ethereum.ChainReader + bind.ContractBackend +} + +type evmDownloaderInterface interface { + waitForNewBlocks(ctx context.Context, lastBlockSeen uint64) (newLastBlock uint64) + getEventsByBlockRange(ctx context.Context, fromBlock, toBlock uint64) []EVMBlock + getLogs(ctx context.Context, fromBlock, toBlock uint64) []types.Log + getBlockHeader(ctx context.Context, blockNum uint64) EVMBlockHeader +} + +type LogAppenderMap map[common.Hash]func(b *EVMBlock, l types.Log) error + +type EVMDownloader struct { + syncBlockChunkSize uint64 + evmDownloaderInterface +} + +func NewEVMDownloader( + ethClient EthClienter, + syncBlockChunkSize uint64, + blockFinalityType etherman.BlockNumberFinality, + waitForNewBlocksPeriod time.Duration, + appender LogAppenderMap, + adressessToQuery []common.Address, +) (*EVMDownloader, error) { + finality, err := blockFinalityType.ToBlockNum() + if err != nil { + return nil, err + } + topicsToQuery := [][]common.Hash{} + for topic := range appender { + topicsToQuery = append(topicsToQuery, []common.Hash{topic}) + } + return &EVMDownloader{ + syncBlockChunkSize: syncBlockChunkSize, + evmDownloaderInterface: &downloaderImplementation{ + ethClient: ethClient, + blockFinality: finality, + waitForNewBlocksPeriod: waitForNewBlocksPeriod, + appender: appender, + topicsToQuery: topicsToQuery, + adressessToQuery: adressessToQuery, + }, + }, nil +} + +func (d *EVMDownloader) download(ctx context.Context, fromBlock uint64, downloadedCh chan EVMBlock) { + lastBlock := d.waitForNewBlocks(ctx, 0) + for { + select { + case <-ctx.Done(): + log.Debug("closing channel") + close(downloadedCh) + return + default: + } + toBlock := fromBlock + d.syncBlockChunkSize + if toBlock > lastBlock { + toBlock = lastBlock + } + if fromBlock > toBlock { + log.Debug("waiting for new blocks, last block ", toBlock) + lastBlock = d.waitForNewBlocks(ctx, toBlock) + continue + } + log.Debugf("getting events from blocks %d to %d", fromBlock, toBlock) + blocks := d.getEventsByBlockRange(ctx, fromBlock, toBlock) + for _, b := range blocks { + log.Debugf("sending block %d to the driver (with events)", b.Num) + downloadedCh <- b + } + if len(blocks) == 0 || blocks[len(blocks)-1].Num < toBlock { + // Indicate the last downloaded block if there are not events on it + log.Debugf("sending block %d to the driver (without evvents)", toBlock) + downloadedCh <- EVMBlock{ + EVMBlockHeader: d.getBlockHeader(ctx, toBlock), + } + } + fromBlock = toBlock + 1 + } +} + +type downloaderImplementation struct { + ethClient EthClienter + blockFinality *big.Int + waitForNewBlocksPeriod time.Duration + appender LogAppenderMap + topicsToQuery [][]common.Hash + adressessToQuery []common.Address +} + +func (d *downloaderImplementation) waitForNewBlocks(ctx context.Context, lastBlockSeen uint64) (newLastBlock uint64) { + attempts := 0 + for { + header, err := d.ethClient.HeaderByNumber(ctx, d.blockFinality) + if err != nil { + attempts++ + log.Error("error geting last block num from eth client: ", err) + RetryHandler("waitForNewBlocks", attempts) + continue + } + if header.Number.Uint64() > lastBlockSeen { + return header.Number.Uint64() + } + time.Sleep(d.waitForNewBlocksPeriod) + } +} + +func (d *downloaderImplementation) getEventsByBlockRange(ctx context.Context, fromBlock, toBlock uint64) []EVMBlock { + blocks := []EVMBlock{} + logs := d.getLogs(ctx, fromBlock, toBlock) + for _, l := range logs { + if len(blocks) == 0 || blocks[len(blocks)-1].Num < l.BlockNumber { + b := d.getBlockHeader(ctx, l.BlockNumber) + blocks = append(blocks, EVMBlock{ + EVMBlockHeader: EVMBlockHeader{ + Num: l.BlockNumber, + Hash: l.BlockHash, + Timestamp: b.Timestamp, + ParentHash: b.ParentHash, + }, + Events: []interface{}{}, + }) + } + + for { + attempts := 0 + err := d.appender[l.Topics[0]](&blocks[len(blocks)-1], l) + if err != nil { + attempts++ + log.Error("error trying to append log: ", err) + RetryHandler("getLogs", attempts) + continue + } + break + } + } + + return blocks +} + +func (d *downloaderImplementation) getLogs(ctx context.Context, fromBlock, toBlock uint64) []types.Log { + query := ethereum.FilterQuery{ + FromBlock: new(big.Int).SetUint64(fromBlock), + Addresses: d.adressessToQuery, + Topics: d.topicsToQuery, + ToBlock: new(big.Int).SetUint64(toBlock), + } + attempts := 0 + for { + logs, err := d.ethClient.FilterLogs(ctx, query) + if err != nil { + attempts++ + log.Error("error calling FilterLogs to eth client: ", err) + RetryHandler("getLogs", attempts) + continue + } + return logs + } +} + +func (d *downloaderImplementation) getBlockHeader(ctx context.Context, blockNum uint64) EVMBlockHeader { + attempts := 0 + for { + header, err := d.ethClient.HeaderByNumber(ctx, big.NewInt(int64(blockNum))) + if err != nil { + attempts++ + log.Errorf("error getting block header for block %d, err: %v", blockNum, err) + RetryHandler("getBlockHeader", attempts) + continue + } + return EVMBlockHeader{ + Num: header.Number.Uint64(), + Hash: header.Hash(), + ParentHash: header.ParentHash, + Timestamp: header.Time, + } + } +} diff --git a/l1infotreesync/downloader_test.go b/sync/evmdownloader_test.go similarity index 72% rename from l1infotreesync/downloader_test.go rename to sync/evmdownloader_test.go index 28daf69b..c733aabd 100644 --- a/l1infotreesync/downloader_test.go +++ b/sync/evmdownloader_test.go @@ -1,9 +1,10 @@ -package l1infotreesync +package sync import ( "context" "errors" "math/big" + "strconv" "testing" "time" @@ -12,31 +13,33 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) var ( - contractAddr = common.HexToAddress("1234567890") + contractAddr = common.HexToAddress("f00") + eventSignature = crypto.Keccak256Hash([]byte("foo")) ) const ( syncBlockChunck = uint64(10) ) +type testEvent common.Hash + func TestGetEventsByBlockRange(t *testing.T) { type testCase struct { description string inputLogs []types.Log fromBlock, toBlock uint64 - expectedBlocks []block + expectedBlocks []EVMBlock } testCases := []testCase{} - clientMock := NewL2Mock(t) ctx := context.Background() - d, err := newDownloader(contractAddr, clientMock, syncBlockChunck, etherman.LatestBlock) - require.NoError(t, err) + d, clientMock := NewTestDownloader(t) // case 0: single block, no events case0 := testCase{ @@ -44,25 +47,23 @@ func TestGetEventsByBlockRange(t *testing.T) { inputLogs: []types.Log{}, fromBlock: 1, toBlock: 3, - expectedBlocks: []block{}, + expectedBlocks: []EVMBlock{}, } testCases = append(testCases, case0) // case 1: single block, single event - logC1, updateC1 := generateUpdateL1InfoTree(t, 3) + logC1, updateC1 := generateEvent(3) logsC1 := []types.Log{ *logC1, } - blocksC1 := []block{ + blocksC1 := []EVMBlock{ { - blockHeader: blockHeader{ + EVMBlockHeader: EVMBlockHeader{ Num: logC1.BlockNumber, Hash: logC1.BlockHash, ParentHash: common.HexToHash("foo"), }, - Events: []L1InfoTreeUpdate{ - updateC1, - }, + Events: []interface{}{updateC1}, }, } case1 := testCase{ @@ -75,24 +76,24 @@ func TestGetEventsByBlockRange(t *testing.T) { testCases = append(testCases, case1) // case 2: single block, multiple events - logC2_1, updateC2_1 := generateUpdateL1InfoTree(t, 5) - logC2_2, updateC2_2 := generateUpdateL1InfoTree(t, 5) - logC2_3, updateC2_3 := generateUpdateL1InfoTree(t, 5) - logC2_4, updateC2_4 := generateUpdateL1InfoTree(t, 5) + logC2_1, updateC2_1 := generateEvent(5) + logC2_2, updateC2_2 := generateEvent(5) + logC2_3, updateC2_3 := generateEvent(5) + logC2_4, updateC2_4 := generateEvent(5) logsC2 := []types.Log{ *logC2_1, *logC2_2, *logC2_3, *logC2_4, } - blocksC2 := []block{ + blocksC2 := []EVMBlock{ { - blockHeader: blockHeader{ + EVMBlockHeader: EVMBlockHeader{ Num: logC2_1.BlockNumber, Hash: logC2_1.BlockHash, ParentHash: common.HexToHash("foo"), }, - Events: []L1InfoTreeUpdate{ + Events: []interface{}{ updateC2_1, updateC2_2, updateC2_3, @@ -110,35 +111,35 @@ func TestGetEventsByBlockRange(t *testing.T) { testCases = append(testCases, case2) // case 3: multiple blocks, some events - logC3_1, updateC3_1 := generateUpdateL1InfoTree(t, 7) - logC3_2, updateC3_2 := generateUpdateL1InfoTree(t, 7) - logC3_3, updateC3_3 := generateUpdateL1InfoTree(t, 8) - logC3_4, updateC3_4 := generateUpdateL1InfoTree(t, 8) + logC3_1, updateC3_1 := generateEvent(7) + logC3_2, updateC3_2 := generateEvent(7) + logC3_3, updateC3_3 := generateEvent(8) + logC3_4, updateC3_4 := generateEvent(8) logsC3 := []types.Log{ *logC3_1, *logC3_2, *logC3_3, *logC3_4, } - blocksC3 := []block{ + blocksC3 := []EVMBlock{ { - blockHeader: blockHeader{ + EVMBlockHeader: EVMBlockHeader{ Num: logC3_1.BlockNumber, Hash: logC3_1.BlockHash, ParentHash: common.HexToHash("foo"), }, - Events: []L1InfoTreeUpdate{ + Events: []interface{}{ updateC3_1, updateC3_2, }, }, { - blockHeader: blockHeader{ + EVMBlockHeader: EVMBlockHeader{ Num: logC3_3.BlockNumber, Hash: logC3_3.BlockHash, ParentHash: common.HexToHash("foo"), }, - Events: []L1InfoTreeUpdate{ + Events: []interface{}{ updateC3_3, updateC3_4, }, @@ -158,7 +159,7 @@ func TestGetEventsByBlockRange(t *testing.T) { FromBlock: new(big.Int).SetUint64(tc.fromBlock), Addresses: []common.Address{contractAddr}, Topics: [][]common.Hash{ - {updateL1InfoTreeSignature}, + {eventSignature}, }, ToBlock: new(big.Int).SetUint64(tc.toBlock), } @@ -179,26 +180,19 @@ func TestGetEventsByBlockRange(t *testing.T) { } } -func generateUpdateL1InfoTree(t *testing.T, blockNum uint32) (*types.Log, L1InfoTreeUpdate) { - b := L1InfoTreeUpdate{ - MainnetExitRoot: common.BigToHash(big.NewInt(int64(blockNum))), - RollupExitRoot: common.BigToHash(big.NewInt(int64(blockNum))), - } - var rollup, mainnet [32]byte - mainnet = b.MainnetExitRoot - rollup = b.RollupExitRoot +func generateEvent(blockNum uint32) (*types.Log, testEvent) { + h := common.HexToHash(strconv.Itoa(int(blockNum))) log := &types.Log{ Address: contractAddr, BlockNumber: uint64(blockNum), - BlockHash: common.BytesToHash(uint64ToBytes(uint64(blockNum))), + BlockHash: h, Topics: []common.Hash{ - updateL1InfoTreeSignature, - mainnet, - rollup, + eventSignature, + h, }, Data: nil, } - return log, b + return log, testEvent(h) } func TestDownload(t *testing.T) { @@ -206,31 +200,29 @@ func TestDownload(t *testing.T) { NOTE: due to the concurrent nature of this test (the function being tested runs through a goroutine) if the mock doesn't match, the goroutine will get stuck and the test will timeout */ - d := NewDownloaderMock(t) - downloadCh := make(chan block, 1) + d := NewEVMDownloaderMock(t) + downloadCh := make(chan EVMBlock, 1) ctx := context.Background() ctx1, cancel := context.WithCancel(ctx) - expectedBlocks := []block{} - clientMock := NewL2Mock(t) - dwnldr, err := newDownloader(contractAddr, clientMock, syncBlockChunck, etherman.LatestBlock) - require.NoError(t, err) - dwnldr.downloaderInterface = d + expectedBlocks := []EVMBlock{} + dwnldr, _ := NewTestDownloader(t) + dwnldr.evmDownloaderInterface = d d.On("waitForNewBlocks", mock.Anything, uint64(0)). Return(uint64(1)) // iteratiion 0: // last block is 1, download that block (no events and wait) - b1 := block{ - blockHeader: blockHeader{ + b1 := EVMBlock{ + EVMBlockHeader: EVMBlockHeader{ Num: 1, Hash: common.HexToHash("01"), }, } expectedBlocks = append(expectedBlocks, b1) d.On("getEventsByBlockRange", mock.Anything, uint64(0), uint64(1)). - Return([]block{}) + Return([]EVMBlock{}) d.On("getBlockHeader", mock.Anything, uint64(1)). - Return(b1.blockHeader) + Return(b1.EVMBlockHeader) // iteration 1: wait for next block to be created d.On("waitForNewBlocks", mock.Anything, uint64(1)). @@ -238,15 +230,15 @@ func TestDownload(t *testing.T) { Return(uint64(2)).Once() // iteration 2: block 2 has events - b2 := block{ - blockHeader: blockHeader{ + b2 := EVMBlock{ + EVMBlockHeader: EVMBlockHeader{ Num: 2, Hash: common.HexToHash("02"), }, } expectedBlocks = append(expectedBlocks, b2) d.On("getEventsByBlockRange", mock.Anything, uint64(2), uint64(2)). - Return([]block{b2}) + Return([]EVMBlock{b2}) // iteration 3: wait for next block to be created (jump to block 8) d.On("waitForNewBlocks", mock.Anything, uint64(2)). @@ -254,35 +246,31 @@ func TestDownload(t *testing.T) { Return(uint64(8)).Once() // iteration 4: blocks 6 and 7 have events - b6 := block{ - blockHeader: blockHeader{ + b6 := EVMBlock{ + EVMBlockHeader: EVMBlockHeader{ Num: 6, Hash: common.HexToHash("06"), }, - Events: []L1InfoTreeUpdate{ - {RollupExitRoot: common.HexToHash("06")}, - }, + Events: []interface{}{"06"}, } - b7 := block{ - blockHeader: blockHeader{ + b7 := EVMBlock{ + EVMBlockHeader: EVMBlockHeader{ Num: 7, Hash: common.HexToHash("07"), }, - Events: []L1InfoTreeUpdate{ - {MainnetExitRoot: common.HexToHash("07")}, - }, + Events: []interface{}{"07"}, } - b8 := block{ - blockHeader: blockHeader{ + b8 := EVMBlock{ + EVMBlockHeader: EVMBlockHeader{ Num: 8, Hash: common.HexToHash("08"), }, } expectedBlocks = append(expectedBlocks, b6, b7, b8) d.On("getEventsByBlockRange", mock.Anything, uint64(3), uint64(8)). - Return([]block{b6, b7}) + Return([]EVMBlock{b6, b7}) d.On("getBlockHeader", mock.Anything, uint64(8)). - Return(b8.blockHeader) + Return(b8.EVMBlockHeader) // iteration 5: wait for next block to be created (jump to block 30) d.On("waitForNewBlocks", mock.Anything, uint64(8)). @@ -290,31 +278,29 @@ func TestDownload(t *testing.T) { Return(uint64(30)).Once() // iteration 6: from block 9 to 19, no events - b19 := block{ - blockHeader: blockHeader{ + b19 := EVMBlock{ + EVMBlockHeader: EVMBlockHeader{ Num: 19, Hash: common.HexToHash("19"), }, } expectedBlocks = append(expectedBlocks, b19) d.On("getEventsByBlockRange", mock.Anything, uint64(9), uint64(19)). - Return([]block{}) + Return([]EVMBlock{}) d.On("getBlockHeader", mock.Anything, uint64(19)). - Return(b19.blockHeader) + Return(b19.EVMBlockHeader) // iteration 7: from block 20 to 30, events on last block - b30 := block{ - blockHeader: blockHeader{ + b30 := EVMBlock{ + EVMBlockHeader: EVMBlockHeader{ Num: 30, Hash: common.HexToHash("30"), }, - Events: []L1InfoTreeUpdate{ - {RollupExitRoot: common.HexToHash("30")}, - }, + Events: []interface{}{testEvent(common.HexToHash("30"))}, } expectedBlocks = append(expectedBlocks, b30) d.On("getEventsByBlockRange", mock.Anything, uint64(20), uint64(30)). - Return([]block{b30}) + Return([]EVMBlock{b30}) // iteration 8: wait for next block to be created (jump to block 35) d.On("waitForNewBlocks", mock.Anything, uint64(30)). @@ -334,11 +320,9 @@ func TestDownload(t *testing.T) { } func TestWaitForNewBlocks(t *testing.T) { - retryAfterErrorPeriod = time.Millisecond * 100 - clientMock := NewL2Mock(t) + RetryAfterErrorPeriod = time.Millisecond * 100 ctx := context.Background() - d, err := newDownloader(contractAddr, clientMock, syncBlockChunck, etherman.LatestBlock) - require.NoError(t, err) + d, clientMock := NewTestDownloader(t) // at first attempt currentBlock := uint64(5) @@ -369,18 +353,16 @@ func TestWaitForNewBlocks(t *testing.T) { } func TestGetBlockHeader(t *testing.T) { - retryAfterErrorPeriod = time.Millisecond * 100 - clientMock := NewL2Mock(t) + RetryAfterErrorPeriod = time.Millisecond * 100 ctx := context.Background() - d, err := newDownloader(contractAddr, clientMock, syncBlockChunck, etherman.LatestBlock) - require.NoError(t, err) + d, clientMock := NewTestDownloader(t) blockNum := uint64(5) blockNumBig := big.NewInt(5) returnedBlock := &types.Header{ Number: blockNumBig, } - expectedBlock := blockHeader{ + expectedBlock := EVMBlockHeader{ Num: 5, Hash: returnedBlock.Hash(), } @@ -396,3 +378,19 @@ func TestGetBlockHeader(t *testing.T) { actualBlock = d.getBlockHeader(ctx, blockNum) assert.Equal(t, expectedBlock, actualBlock) } + +func buildAppender() LogAppenderMap { + appender := make(LogAppenderMap) + appender[eventSignature] = func(b *EVMBlock, l types.Log) error { + b.Events = append(b.Events, testEvent(l.Topics[1])) + return nil + } + return appender +} + +func NewTestDownloader(t *testing.T) (*EVMDownloader, *L2Mock) { + clientMock := NewL2Mock(t) + d, err := NewEVMDownloader(clientMock, syncBlockChunck, etherman.LatestBlock, time.Millisecond, buildAppender(), []common.Address{contractAddr}) + require.NoError(t, err) + return d, clientMock +} diff --git a/localbridgesync/driver.go b/sync/evmdriver.go similarity index 54% rename from localbridgesync/driver.go rename to sync/evmdriver.go index eaeed1c7..0363e00c 100644 --- a/localbridgesync/driver.go +++ b/sync/evmdriver.go @@ -1,4 +1,4 @@ -package localbridgesync +package sync import ( "context" @@ -8,27 +8,24 @@ import ( "github.com/ethereum/go-ethereum/common" ) -const ( - downloadBufferSize = 1000 - reorgDetectorID = "localbridgesync" -) - -type downloaderFull interface { - downloaderInterface - download(ctx context.Context, fromBlock uint64, downloadedCh chan block) +type evmDownloaderFull interface { + evmDownloaderInterface + download(ctx context.Context, fromBlock uint64, downloadedCh chan EVMBlock) } -type driver struct { - reorgDetector ReorgDetector - reorgSub *reorgdetector.Subscription - processor processorInterface - downloader downloaderFull +type EVMDriver struct { + reorgDetector ReorgDetector + reorgSub *reorgdetector.Subscription + processor processorInterface + downloader evmDownloaderFull + reorgDetectorID string + downloadBufferSize int } type processorInterface interface { - getLastProcessedBlock(ctx context.Context) (uint64, error) - storeBridgeEvents(blockNum uint64, events []BridgeEvent) error - reorg(firstReorgedBlock uint64) error + GetLastProcessedBlock(ctx context.Context) (uint64, error) + ProcessBlock(block EVMBlock) error + Reorg(firstReorgedBlock uint64) error } type ReorgDetector interface { @@ -36,24 +33,28 @@ type ReorgDetector interface { AddBlockToTrack(ctx context.Context, id string, blockNum uint64, blockHash common.Hash) error } -func newDriver( +func NewEVMDriver( reorgDetector ReorgDetector, processor processorInterface, - downloader downloaderFull, -) (*driver, error) { + downloader evmDownloaderFull, + reorgDetectorID string, + downloadBufferSize int, +) (*EVMDriver, error) { reorgSub, err := reorgDetector.Subscribe(reorgDetectorID) if err != nil { return nil, err } - return &driver{ - reorgDetector: reorgDetector, - reorgSub: reorgSub, - processor: processor, - downloader: downloader, + return &EVMDriver{ + reorgDetector: reorgDetector, + reorgSub: reorgSub, + processor: processor, + downloader: downloader, + reorgDetectorID: reorgDetectorID, + downloadBufferSize: downloadBufferSize, }, nil } -func (d *driver) Sync(ctx context.Context) { +func (d *EVMDriver) Sync(ctx context.Context) { reset: var ( lastProcessedBlock uint64 @@ -61,11 +62,11 @@ reset: err error ) for { - lastProcessedBlock, err = d.processor.getLastProcessedBlock(ctx) + lastProcessedBlock, err = d.processor.GetLastProcessedBlock(ctx) if err != nil { attempts++ log.Error("error geting last processed block: ", err) - retryHandler("Sync", attempts) + RetryHandler("Sync", attempts) continue } break @@ -74,7 +75,7 @@ reset: defer cancel() // start downloading - downloadCh := make(chan block, downloadBufferSize) + downloadCh := make(chan EVMBlock, d.downloadBufferSize) go d.downloader.download(cancellableCtx, lastProcessedBlock, downloadCh) for { @@ -90,33 +91,33 @@ reset: } } -func (d *driver) handleNewBlock(ctx context.Context, b block) { +func (d *EVMDriver) handleNewBlock(ctx context.Context, b EVMBlock) { attempts := 0 for { - err := d.reorgDetector.AddBlockToTrack(ctx, reorgDetectorID, b.Num, b.Hash) + err := d.reorgDetector.AddBlockToTrack(ctx, d.reorgDetectorID, b.Num, b.Hash) if err != nil { attempts++ log.Errorf("error adding block %d to tracker: %v", b.Num, err) - retryHandler("handleNewBlock", attempts) + RetryHandler("handleNewBlock", attempts) continue } break } attempts = 0 for { - err := d.processor.storeBridgeEvents(b.Num, b.Events) + err := d.processor.ProcessBlock(b) if err != nil { attempts++ log.Errorf("error processing events for blcok %d, err: ", b.Num, err) - retryHandler("handleNewBlock", attempts) + RetryHandler("handleNewBlock", attempts) continue } break } } -func (d *driver) handleReorg( - cancel context.CancelFunc, downloadCh chan block, firstReorgedBlock uint64, +func (d *EVMDriver) handleReorg( + cancel context.CancelFunc, downloadCh chan EVMBlock, firstReorgedBlock uint64, ) { // stop downloader cancel() @@ -127,14 +128,14 @@ func (d *driver) handleReorg( // handle reorg attempts := 0 for { - err := d.processor.reorg(firstReorgedBlock) + err := d.processor.Reorg(firstReorgedBlock) if err != nil { attempts++ log.Errorf( - "error processing reorg, last valid block %d, err: %v", + "error processing reorg, last valid Block %d, err: %v", firstReorgedBlock, err, ) - retryHandler("handleReorg", attempts) + RetryHandler("handleReorg", attempts) continue } break diff --git a/localbridgesync/driver_test.go b/sync/evmdriver_test.go similarity index 77% rename from localbridgesync/driver_test.go rename to sync/evmdriver_test.go index 543542f7..1f063cdb 100644 --- a/localbridgesync/driver_test.go +++ b/sync/evmdriver_test.go @@ -1,4 +1,4 @@ -package localbridgesync +package sync import ( "context" @@ -14,28 +14,32 @@ import ( "github.com/stretchr/testify/require" ) +var ( + reorgDetectorID = "foo" +) + func TestSync(t *testing.T) { - retryAfterErrorPeriod = time.Millisecond * 100 + RetryAfterErrorPeriod = time.Millisecond * 100 rdm := NewReorgDetectorMock(t) pm := NewProcessorMock(t) - dm := NewDownloaderMock(t) + dm := NewEVMDownloaderMock(t) firstReorgedBlock := make(chan uint64) reorgProcessed := make(chan bool) rdm.On("Subscribe", reorgDetectorID).Return(&reorgdetector.Subscription{ FirstReorgedBlock: firstReorgedBlock, ReorgProcessed: reorgProcessed, - }) - driver, err := newDriver(rdm, pm, dm) + }, nil) + driver, err := NewEVMDriver(rdm, pm, dm, reorgDetectorID, 10) require.NoError(t, err) ctx := context.Background() - expectedBlock1 := block{ - blockHeader: blockHeader{ + expectedBlock1 := EVMBlock{ + EVMBlockHeader: EVMBlockHeader{ Num: 3, Hash: common.HexToHash("03"), }, } - expectedBlock2 := block{ - blockHeader: blockHeader{ + expectedBlock2 := EVMBlock{ + EVMBlockHeader: EVMBlockHeader{ Num: 9, Hash: common.HexToHash("09"), }, @@ -47,7 +51,7 @@ func TestSync(t *testing.T) { reorg1Completed := reorgSemaphore{} dm.On("download", mock.Anything, mock.Anything, mock.Anything).Run(func(args mock.Arguments) { ctx := args.Get(0).(context.Context) - downloadedCh := args.Get(2).(chan block) + downloadedCh := args.Get(2).(chan EVMBlock) log.Info("entering mock loop") for { select { @@ -70,22 +74,22 @@ func TestSync(t *testing.T) { }) // Mocking this actions, the driver should "store" all the blocks from the downloader - pm.On("getLastProcessedBlock", ctx). + pm.On("GetLastProcessedBlock", ctx). Return(uint64(3), nil) rdm.On("AddBlockToTrack", ctx, reorgDetectorID, expectedBlock1.Num, expectedBlock1.Hash). Return(nil) - pm.On("storeBridgeEvents", expectedBlock1.Num, expectedBlock1.Events). + pm.On("ProcessBlock", expectedBlock1). Return(nil) rdm.On("AddBlockToTrack", ctx, reorgDetectorID, expectedBlock2.Num, expectedBlock2.Hash). Return(nil) - pm.On("storeBridgeEvents", expectedBlock2.Num, expectedBlock2.Events). + pm.On("ProcessBlock", expectedBlock2). Return(nil) go driver.Sync(ctx) time.Sleep(time.Millisecond * 200) // time to download expectedBlock1 // Trigger reorg 1 reorgedBlock1 := uint64(5) - pm.On("reorg", reorgedBlock1).Return(nil) + pm.On("Reorg", reorgedBlock1).Return(nil) firstReorgedBlock <- reorgedBlock1 ok := <-reorgProcessed require.True(t, ok) @@ -96,25 +100,25 @@ func TestSync(t *testing.T) { // Trigger reorg 2: syncer restarts the porcess reorgedBlock2 := uint64(7) - pm.On("reorg", reorgedBlock2).Return(nil) + pm.On("Reorg", reorgedBlock2).Return(nil) firstReorgedBlock <- reorgedBlock2 ok = <-reorgProcessed require.True(t, ok) } func TestHandleNewBlock(t *testing.T) { - retryAfterErrorPeriod = time.Millisecond * 100 + RetryAfterErrorPeriod = time.Millisecond * 100 rdm := NewReorgDetectorMock(t) pm := NewProcessorMock(t) - dm := NewDownloaderMock(t) - rdm.On("Subscribe", reorgDetectorID).Return(&reorgdetector.Subscription{}) - driver, err := newDriver(rdm, pm, dm) + dm := NewEVMDownloaderMock(t) + rdm.On("Subscribe", reorgDetectorID).Return(&reorgdetector.Subscription{}, nil) + driver, err := NewEVMDriver(rdm, pm, dm, reorgDetectorID, 10) require.NoError(t, err) ctx := context.Background() // happy path - b1 := block{ - blockHeader: blockHeader{ + b1 := EVMBlock{ + EVMBlockHeader: EVMBlockHeader{ Num: 1, Hash: common.HexToHash("f00"), }, @@ -122,13 +126,13 @@ func TestHandleNewBlock(t *testing.T) { rdm. On("AddBlockToTrack", ctx, reorgDetectorID, b1.Num, b1.Hash). Return(nil) - pm.On("storeBridgeEvents", b1.Num, b1.Events). + pm.On("ProcessBlock", b1). Return(nil) driver.handleNewBlock(ctx, b1) // reorg deteector fails once - b2 := block{ - blockHeader: blockHeader{ + b2 := EVMBlock{ + EVMBlockHeader: EVMBlockHeader{ Num: 2, Hash: common.HexToHash("f00"), }, @@ -139,13 +143,13 @@ func TestHandleNewBlock(t *testing.T) { rdm. On("AddBlockToTrack", ctx, reorgDetectorID, b2.Num, b2.Hash). Return(nil).Once() - pm.On("storeBridgeEvents", b2.Num, b2.Events). + pm.On("ProcessBlock", b2). Return(nil) driver.handleNewBlock(ctx, b2) // processor fails once - b3 := block{ - blockHeader: blockHeader{ + b3 := EVMBlock{ + EVMBlockHeader: EVMBlockHeader{ Num: 3, Hash: common.HexToHash("f00"), }, @@ -153,30 +157,30 @@ func TestHandleNewBlock(t *testing.T) { rdm. On("AddBlockToTrack", ctx, reorgDetectorID, b3.Num, b3.Hash). Return(nil) - pm.On("storeBridgeEvents", b3.Num, b3.Events). + pm.On("ProcessBlock", b3). Return(errors.New("foo")).Once() - pm.On("storeBridgeEvents", b3.Num, b3.Events). + pm.On("ProcessBlock", b3). Return(nil).Once() driver.handleNewBlock(ctx, b3) } func TestHandleReorg(t *testing.T) { - retryAfterErrorPeriod = time.Millisecond * 100 + RetryAfterErrorPeriod = time.Millisecond * 100 rdm := NewReorgDetectorMock(t) pm := NewProcessorMock(t) - dm := NewDownloaderMock(t) + dm := NewEVMDownloaderMock(t) reorgProcessed := make(chan bool) rdm.On("Subscribe", reorgDetectorID).Return(&reorgdetector.Subscription{ ReorgProcessed: reorgProcessed, - }) - driver, err := newDriver(rdm, pm, dm) + }, nil) + driver, err := NewEVMDriver(rdm, pm, dm, reorgDetectorID, 10) require.NoError(t, err) ctx := context.Background() // happy path _, cancel := context.WithCancel(ctx) - downloadCh := make(chan block) + downloadCh := make(chan EVMBlock) firstReorgedBlock := uint64(5) pm.On("reorg", firstReorgedBlock).Return(nil) go driver.handleReorg(cancel, downloadCh, firstReorgedBlock) @@ -186,20 +190,20 @@ func TestHandleReorg(t *testing.T) { // download ch sends some garbage _, cancel = context.WithCancel(ctx) - downloadCh = make(chan block) + downloadCh = make(chan EVMBlock) firstReorgedBlock = uint64(6) pm.On("reorg", firstReorgedBlock).Return(nil) go driver.handleReorg(cancel, downloadCh, firstReorgedBlock) - downloadCh <- block{} - downloadCh <- block{} - downloadCh <- block{} + downloadCh <- EVMBlock{} + downloadCh <- EVMBlock{} + downloadCh <- EVMBlock{} close(downloadCh) done = <-reorgProcessed require.True(t, done) // processor fails 2 times _, cancel = context.WithCancel(ctx) - downloadCh = make(chan block) + downloadCh = make(chan EVMBlock) firstReorgedBlock = uint64(7) pm.On("reorg", firstReorgedBlock).Return(errors.New("foo")).Once() pm.On("reorg", firstReorgedBlock).Return(errors.New("foo")).Once() diff --git a/sync/evmtypes.go b/sync/evmtypes.go new file mode 100644 index 00000000..d242dbc4 --- /dev/null +++ b/sync/evmtypes.go @@ -0,0 +1,15 @@ +package sync + +import "github.com/ethereum/go-ethereum/common" + +type EVMBlock struct { + EVMBlockHeader + Events []interface{} +} + +type EVMBlockHeader struct { + Num uint64 + Hash common.Hash + ParentHash common.Hash + Timestamp uint64 +} diff --git a/l1infotreesync/mock_downloader_test.go b/sync/mock_downloader_test.go similarity index 54% rename from l1infotreesync/mock_downloader_test.go rename to sync/mock_downloader_test.go index fca72678..738fc873 100644 --- a/l1infotreesync/mock_downloader_test.go +++ b/sync/mock_downloader_test.go @@ -1,6 +1,6 @@ // Code generated by mockery v2.22.1. DO NOT EDIT. -package l1infotreesync +package sync import ( context "context" @@ -9,45 +9,40 @@ import ( mock "github.com/stretchr/testify/mock" ) -// DownloaderMock is an autogenerated mock type for the downloaderFull type -type DownloaderMock struct { +// EVMDownloaderMock is an autogenerated mock type for the evmDownloaderFull type +type EVMDownloaderMock struct { mock.Mock } -// appendLog provides a mock function with given fields: b, l -func (_m *DownloaderMock) appendLog(b *block, l types.Log) { - _m.Called(b, l) -} - // download provides a mock function with given fields: ctx, fromBlock, downloadedCh -func (_m *DownloaderMock) download(ctx context.Context, fromBlock uint64, downloadedCh chan block) { +func (_m *EVMDownloaderMock) download(ctx context.Context, fromBlock uint64, downloadedCh chan EVMBlock) { _m.Called(ctx, fromBlock, downloadedCh) } // getBlockHeader provides a mock function with given fields: ctx, blockNum -func (_m *DownloaderMock) getBlockHeader(ctx context.Context, blockNum uint64) blockHeader { +func (_m *EVMDownloaderMock) getBlockHeader(ctx context.Context, blockNum uint64) EVMBlockHeader { ret := _m.Called(ctx, blockNum) - var r0 blockHeader - if rf, ok := ret.Get(0).(func(context.Context, uint64) blockHeader); ok { + var r0 EVMBlockHeader + if rf, ok := ret.Get(0).(func(context.Context, uint64) EVMBlockHeader); ok { r0 = rf(ctx, blockNum) } else { - r0 = ret.Get(0).(blockHeader) + r0 = ret.Get(0).(EVMBlockHeader) } return r0 } // getEventsByBlockRange provides a mock function with given fields: ctx, fromBlock, toBlock -func (_m *DownloaderMock) getEventsByBlockRange(ctx context.Context, fromBlock uint64, toBlock uint64) []block { +func (_m *EVMDownloaderMock) getEventsByBlockRange(ctx context.Context, fromBlock uint64, toBlock uint64) []EVMBlock { ret := _m.Called(ctx, fromBlock, toBlock) - var r0 []block - if rf, ok := ret.Get(0).(func(context.Context, uint64, uint64) []block); ok { + var r0 []EVMBlock + if rf, ok := ret.Get(0).(func(context.Context, uint64, uint64) []EVMBlock); ok { r0 = rf(ctx, fromBlock, toBlock) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]block) + r0 = ret.Get(0).([]EVMBlock) } } @@ -55,7 +50,7 @@ func (_m *DownloaderMock) getEventsByBlockRange(ctx context.Context, fromBlock u } // getLogs provides a mock function with given fields: ctx, fromBlock, toBlock -func (_m *DownloaderMock) getLogs(ctx context.Context, fromBlock uint64, toBlock uint64) []types.Log { +func (_m *EVMDownloaderMock) getLogs(ctx context.Context, fromBlock uint64, toBlock uint64) []types.Log { ret := _m.Called(ctx, fromBlock, toBlock) var r0 []types.Log @@ -71,7 +66,7 @@ func (_m *DownloaderMock) getLogs(ctx context.Context, fromBlock uint64, toBlock } // waitForNewBlocks provides a mock function with given fields: ctx, lastBlockSeen -func (_m *DownloaderMock) waitForNewBlocks(ctx context.Context, lastBlockSeen uint64) uint64 { +func (_m *EVMDownloaderMock) waitForNewBlocks(ctx context.Context, lastBlockSeen uint64) uint64 { ret := _m.Called(ctx, lastBlockSeen) var r0 uint64 @@ -84,14 +79,14 @@ func (_m *DownloaderMock) waitForNewBlocks(ctx context.Context, lastBlockSeen ui return r0 } -type mockConstructorTestingTNewDownloaderMock interface { +type mockConstructorTestingTNewEVMDownloaderMock interface { mock.TestingT Cleanup(func()) } -// NewDownloaderMock creates a new instance of DownloaderMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewDownloaderMock(t mockConstructorTestingTNewDownloaderMock) *DownloaderMock { - mock := &DownloaderMock{} +// NewEVMDownloaderMock creates a new instance of EVMDownloaderMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewEVMDownloaderMock(t mockConstructorTestingTNewEVMDownloaderMock) *EVMDownloaderMock { + mock := &EVMDownloaderMock{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/l1infotreesync/mock_l2_test.go b/sync/mock_l2_test.go similarity index 99% rename from l1infotreesync/mock_l2_test.go rename to sync/mock_l2_test.go index 9ab6868d..0d1e03da 100644 --- a/l1infotreesync/mock_l2_test.go +++ b/sync/mock_l2_test.go @@ -1,6 +1,6 @@ // Code generated by mockery v2.22.1. DO NOT EDIT. -package l1infotreesync +package sync import ( context "context" diff --git a/l1infotreesync/mock_processor_test.go b/sync/mock_processor_test.go similarity index 73% rename from l1infotreesync/mock_processor_test.go rename to sync/mock_processor_test.go index f7105850..f0959b29 100644 --- a/l1infotreesync/mock_processor_test.go +++ b/sync/mock_processor_test.go @@ -1,6 +1,6 @@ // Code generated by mockery v2.22.1. DO NOT EDIT. -package l1infotreesync +package sync import ( context "context" @@ -13,8 +13,8 @@ type ProcessorMock struct { mock.Mock } -// getLastProcessedBlock provides a mock function with given fields: ctx -func (_m *ProcessorMock) getLastProcessedBlock(ctx context.Context) (uint64, error) { +// GetLastProcessedBlock provides a mock function with given fields: ctx +func (_m *ProcessorMock) GetLastProcessedBlock(ctx context.Context) (uint64, error) { ret := _m.Called(ctx) var r0 uint64 @@ -37,13 +37,13 @@ func (_m *ProcessorMock) getLastProcessedBlock(ctx context.Context) (uint64, err return r0, r1 } -// processBlock provides a mock function with given fields: block -func (_m *ProcessorMock) processBlock(b block) error { - ret := _m.Called(b) +// ProcessBlock provides a mock function with given fields: block +func (_m *ProcessorMock) ProcessBlock(block EVMBlock) error { + ret := _m.Called(block) var r0 error - if rf, ok := ret.Get(0).(func(block) error); ok { - r0 = rf(b) + if rf, ok := ret.Get(0).(func(EVMBlock) error); ok { + r0 = rf(block) } else { r0 = ret.Error(0) } @@ -51,8 +51,8 @@ func (_m *ProcessorMock) processBlock(b block) error { return r0 } -// reorg provides a mock function with given fields: firstReorgedBlock -func (_m *ProcessorMock) reorg(firstReorgedBlock uint64) error { +// Reorg provides a mock function with given fields: firstReorgedBlock +func (_m *ProcessorMock) Reorg(firstReorgedBlock uint64) error { ret := _m.Called(firstReorgedBlock) var r0 error diff --git a/localbridgesync/mock_reorgdetector_test.go b/sync/mock_reorgdetector_test.go similarity index 98% rename from localbridgesync/mock_reorgdetector_test.go rename to sync/mock_reorgdetector_test.go index 3639cb9a..056da2a1 100644 --- a/localbridgesync/mock_reorgdetector_test.go +++ b/sync/mock_reorgdetector_test.go @@ -1,6 +1,6 @@ // Code generated by mockery v2.22.1. DO NOT EDIT. -package localbridgesync +package sync import ( context "context" diff --git a/test/Makefile b/test/Makefile index 07d49fd3..0e671023 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,15 +1,9 @@ .PHONY: generate-mocks generate-mocks: - $(MAKE) generate-mocks-localbridgesync $(MAKE) generate-mocks-reorgdetector $(MAKE) generate-mocks-l1infotreesync - -.PHONY: generate-mocks-localbridgesync -generate-mocks-localbridgesync: ## Generates mocks for localbridgesync, using mockery tool - export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=EthClienter --dir=../localbridgesync --output=../localbridgesync --outpkg=localbridgesync --inpackage --structname=L2Mock --filename=mock_l2_test.go - export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=downloaderFull --dir=../localbridgesync --output=../localbridgesync --outpkg=localbridgesync --inpackage --structname=DownloaderMock --filename=mock_downloader_test.go - export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=processorInterface --dir=../localbridgesync --output=../localbridgesync --outpkg=localbridgesync --inpackage --structname=ProcessorMock --filename=mock_processor_test.go - export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=ReorgDetector --dir=../localbridgesync --output=../localbridgesync --outpkg=localbridgesync --inpackage --structname=ReorgDetectorMock --filename=mock_reorgdetector_test.go + $(MAKE) generate-mocks-aggoracle + $(MAKE) generate-mocks-sync .PHONY: generate-mocks-reorgdetector generate-mocks-reorgdetector: ## Generates mocks for reorgdetector, using mockery tool @@ -40,11 +34,15 @@ help: ## Prints this help | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' .PHONY: generate-mocks-l1infotreesync generate-mocks-l1infotreesync: ## Generates mocks for l1infotreesync , using mockery tool - export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=EthClienter --dir=../l1infotreesync --output=../l1infotreesync --outpkg=l1infotreesync --inpackage --structname=L2Mock --filename=mock_l2_test.go - export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=downloaderFull --dir=../l1infotreesync --output=../l1infotreesync --outpkg=l1infotreesync --inpackage --structname=DownloaderMock --filename=mock_downloader_test.go - export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=processorInterface --dir=../l1infotreesync --output=../l1infotreesync --outpkg=l1infotreesync --inpackage --structname=ProcessorMock --filename=mock_processor_test.go - export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=ReorgDetector --dir=../l1infotreesync --output=../l1infotreesync --outpkg=l1infotreesync --inpackage --structname=ReorgDetectorMock --filename=mock_reorgdetector_test.go + export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=ReorgDetector --dir=../sync --output=../l1infotreesync --outpkg=l1infotreesync --structname=ReorgDetectorMock --filename=mock_reorgdetector_test.go .PHONY: generate-mocks-aggoracle generate-mocks-aggoracle: ## Generates mocks for aggoracle , using mockery tool export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=EthTxManager --dir=../aggoracle/chaingersender --output=../aggoracle --outpkg=aggoracle --structname=EthTxManagerMock --filename=mock_ethtxmanager_test.go + +.PHONY: generate-mocks-sync +generate-mocks-sync: ## Generates mocks for sync, using mockery tool + export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=EthClienter --dir=../sync --output=../sync --outpkg=sync --inpackage --structname=L2Mock --filename=mock_l2_test.go + export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=evmDownloaderFull --dir=../sync --output=../sync --outpkg=sync --inpackage --structname=EVMDownloaderMock --filename=mock_downloader_test.go + export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=processorInterface --dir=../sync --output=../sync --outpkg=sync --inpackage --structname=ProcessorMock --filename=mock_processor_test.go + export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=ReorgDetector --dir=../sync --output=../sync --outpkg=sync --inpackage --structname=ReorgDetectorMock --filename=mock_reorgdetector_test.go From 4bd7ef1232d02440d79bebb768ca75fcbb372974 Mon Sep 17 00:00:00 2001 From: Arnau Date: Thu, 25 Jul 2024 18:09:01 +0200 Subject: [PATCH 06/18] decouple sync processors from EVM --- aggoracle/e2e_test.go | 2 +- common/common.go | 26 ++++++++--- l1infotreesync/downloader.go | 9 ++-- l1infotreesync/e2e_test.go | 2 +- l1infotreesync/l1infotreesync.go | 14 ++++++ l1infotreesync/processor.go | 70 +++++++++++++++--------------- localbridgesync/downloader.go | 30 ++----------- localbridgesync/localbridgesync.go | 14 ++++++ localbridgesync/processor.go | 50 ++++++++++++++++----- localbridgesync/processor_test.go | 52 +++++++++------------- sync/driver.go | 14 ++++++ sync/evmdriver.go | 8 +++- sync/evmdriver_test.go | 22 +++++----- sync/mock_processor_test.go | 4 +- 14 files changed, 180 insertions(+), 137 deletions(-) create mode 100644 sync/driver.go diff --git a/aggoracle/e2e_test.go b/aggoracle/e2e_test.go index 7d616be9..18b7572d 100644 --- a/aggoracle/e2e_test.go +++ b/aggoracle/e2e_test.go @@ -59,7 +59,7 @@ func commonSetup(t *testing.T) ( require.NoError(t, err) // Syncer dbPathSyncer := t.TempDir() - syncer, err := l1infotreesync.New(ctx, dbPathSyncer, gerL1Addr, 10, etherman.LatestBlock, reorg, l1Client.Client(), 32, time.Millisecond) + syncer, err := l1infotreesync.New(ctx, dbPathSyncer, gerL1Addr, 10, etherman.LatestBlock, reorg, l1Client.Client(), 32, time.Millisecond, 0) require.NoError(t, err) go syncer.Start(ctx) diff --git a/common/common.go b/common/common.go index 4e93d5f8..d2f440d1 100644 --- a/common/common.go +++ b/common/common.go @@ -9,17 +9,29 @@ import ( "github.com/iden3/go-iden3-crypto/keccak256" ) -// BlockNum2Bytes converts a block number to a byte slice -func BlockNum2Bytes(blockNum uint64) []byte { - key := make([]byte, 8) - binary.LittleEndian.PutUint64(key, blockNum) +// Uint64To2Bytes converts a block number to a byte slice +func Uint64To2Bytes(num uint64) []byte { + bytes := make([]byte, 8) + binary.LittleEndian.PutUint64(bytes, num) + return bytes +} + +// BytesToUint64 converts a byte slice to a block number +func BytesToUint64(bytes []byte) uint64 { + return binary.LittleEndian.Uint64(bytes) +} + +// Uint32To2Bytes converts a block number to a byte slice +func Uint32ToBytes(num uint32) []byte { + key := make([]byte, 4) + binary.LittleEndian.PutUint32(key, num) return key } -// Bytes2BlockNum converts a byte slice to a block number -func Bytes2BlockNum(key []byte) uint64 { - return binary.LittleEndian.Uint64(key) +// BytesToUint32 converts a byte slice to a block number +func BytesToUint32(bytes []byte) uint32 { + return binary.LittleEndian.Uint32(bytes) } func CalculateAccInputHash( diff --git a/l1infotreesync/downloader.go b/l1infotreesync/downloader.go index ba9b219b..255395dd 100644 --- a/l1infotreesync/downloader.go +++ b/l1infotreesync/downloader.go @@ -23,11 +23,6 @@ type EthClienter interface { bind.ContractBackend } -type L1InfoTreeUpdate struct { - MainnetExitRoot common.Hash - RollupExitRoot common.Hash -} - func buildAppender(client EthClienter, globalExitRoot common.Address) (sync.LogAppenderMap, error) { contract, err := polygonzkevmglobalexitrootv2.NewPolygonzkevmglobalexitrootv2(globalExitRoot, client) if err != nil { @@ -42,9 +37,11 @@ func buildAppender(client EthClienter, globalExitRoot common.Address) (sync.LogA l, err, ) } - b.Events = append(b.Events, L1InfoTreeUpdate{ + b.Events = append(b.Events, Event{ MainnetExitRoot: l1InfoTreeUpdate.MainnetExitRoot, RollupExitRoot: l1InfoTreeUpdate.RollupExitRoot, + ParentHash: b.ParentHash, + Timestamp: b.Timestamp, }) return nil } diff --git a/l1infotreesync/e2e_test.go b/l1infotreesync/e2e_test.go index dc5734d5..81be3d9a 100644 --- a/l1infotreesync/e2e_test.go +++ b/l1infotreesync/e2e_test.go @@ -54,7 +54,7 @@ func TestE2E(t *testing.T) { rdm.On("AddBlockToTrack", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) client, gerAddr, gerSc, err := newSimulatedClient(auth) require.NoError(t, err) - syncer, err := New(ctx, dbPath, gerAddr, 10, etherman.LatestBlock, rdm, client.Client(), 32, time.Millisecond) + syncer, err := New(ctx, dbPath, gerAddr, 10, etherman.LatestBlock, rdm, client.Client(), 32, time.Millisecond, 0) require.NoError(t, err) go syncer.Start(ctx) diff --git a/l1infotreesync/l1infotreesync.go b/l1infotreesync/l1infotreesync.go index 847488df..695035f3 100644 --- a/l1infotreesync/l1infotreesync.go +++ b/l1infotreesync/l1infotreesync.go @@ -34,11 +34,25 @@ func New( l1Client EthClienter, treeHeight uint8, waitForNewBlocksPeriod time.Duration, + initialBlock uint64, ) (*L1InfoTreeSync, error) { processor, err := newProcessor(ctx, dbPath, treeHeight) if err != nil { return nil, err } + // TODO: get the initialBlock from L1 to simplify config + lastProcessedBlock, err := processor.GetLastProcessedBlock(ctx) + if err != nil { + return nil, err + } + if lastProcessedBlock < initialBlock { + err = processor.ProcessBlock(sync.Block{ + Num: initialBlock, + }) + if err != nil { + return nil, err + } + } appender, err := buildAppender(l1Client, globalExitRoot) if err != nil { diff --git a/l1infotreesync/processor.go b/l1infotreesync/processor.go index 2247fae3..8fea2d60 100644 --- a/l1infotreesync/processor.go +++ b/l1infotreesync/processor.go @@ -6,9 +6,10 @@ import ( "encoding/json" "errors" + "github.com/0xPolygon/cdk/common" "github.com/0xPolygon/cdk/l1infotree" "github.com/0xPolygon/cdk/sync" - "github.com/ethereum/go-ethereum/common" + ethCommon "github.com/ethereum/go-ethereum/common" "github.com/ledgerwatch/erigon-lib/kv" "github.com/ledgerwatch/erigon-lib/kv/mdbx" "golang.org/x/crypto/sha3" @@ -33,22 +34,29 @@ type processor struct { tree *l1infotree.L1InfoTree } +type Event struct { + MainnetExitRoot ethCommon.Hash + RollupExitRoot ethCommon.Hash + ParentHash ethCommon.Hash + Timestamp uint64 +} + type L1InfoTreeLeaf struct { - L1InfoTreeRoot common.Hash + L1InfoTreeRoot ethCommon.Hash L1InfoTreeIndex uint32 - PreviousBlockHash common.Hash + PreviousBlockHash ethCommon.Hash BlockNumber uint64 Timestamp uint64 - MainnetExitRoot common.Hash - RollupExitRoot common.Hash - GlobalExitRoot common.Hash + MainnetExitRoot ethCommon.Hash + RollupExitRoot ethCommon.Hash + GlobalExitRoot ethCommon.Hash } type storeLeaf struct { - MainnetExitRoot common.Hash - RollupExitRoot common.Hash - ParentHash common.Hash - InfoRoot common.Hash + MainnetExitRoot ethCommon.Hash + RollupExitRoot ethCommon.Hash + ParentHash ethCommon.Hash + InfoRoot ethCommon.Hash Index uint32 Timestamp uint64 BlockNumber uint64 @@ -61,7 +69,7 @@ type blockWithLeafs struct { LastIndex uint32 } -func (l *storeLeaf) GlobalExitRoot() common.Hash { +func (l *storeLeaf) GlobalExitRoot() ethCommon.Hash { var gerBytes [32]byte hasher := sha3.NewLegacyKeccak256() hasher.Write(l.MainnetExitRoot[:]) @@ -122,19 +130,19 @@ func (p *processor) getAllLeavesHashed(ctx context.Context) ([][32]byte, error) return p.getHasedLeaves(tx, index) } -func (p *processor) ComputeMerkleProofByIndex(ctx context.Context, index uint32) ([][32]byte, common.Hash, error) { +func (p *processor) ComputeMerkleProofByIndex(ctx context.Context, index uint32) ([][32]byte, ethCommon.Hash, error) { // TODO: refactor the tree to store the nodes so it's not neede to load all the leaves and compute the tree // every time this function is called. Since it's not a sparse MT, an alternative could be to store the proofs // as part of the info tx, err := p.db.BeginRo(ctx) if err != nil { - return nil, common.Hash{}, err + return nil, ethCommon.Hash{}, err } defer tx.Rollback() leaves, err := p.getHasedLeaves(tx, index) if err != nil { - return nil, common.Hash{}, err + return nil, ethCommon.Hash{}, err } return p.tree.ComputeMerkleProof(index, leaves) } @@ -152,15 +160,15 @@ func (p *processor) getHasedLeaves(tx kv.Tx, untilIndex uint32) ([][32]byte, err return leaves, nil } -func (p *processor) ComputeMerkleProofByRoot(ctx context.Context, root common.Hash) ([][32]byte, common.Hash, error) { +func (p *processor) ComputeMerkleProofByRoot(ctx context.Context, root ethCommon.Hash) ([][32]byte, ethCommon.Hash, error) { info, err := p.GetInfoByRoot(ctx, root) if err != nil { - return nil, common.Hash{}, err + return nil, ethCommon.Hash{}, err } return p.ComputeMerkleProofByIndex(ctx, info.L1InfoTreeIndex) } -func (p *processor) GetInfoByRoot(ctx context.Context, root common.Hash) (*L1InfoTreeLeaf, error) { +func (p *processor) GetInfoByRoot(ctx context.Context, root ethCommon.Hash) (*L1InfoTreeLeaf, error) { tx, err := p.db.BeginRo(ctx) if err != nil { return nil, err @@ -205,7 +213,7 @@ func (p *processor) GetLatestInfoUntilBlock(ctx context.Context, blockNum uint64 if err := json.Unmarshal(v, &blk); err != nil { return nil, err } - hash, err := tx.GetOne(indexTable, uint32ToBytes(blk.LastIndex-1)) + hash, err := tx.GetOne(indexTable, common.Uint32ToBytes(blk.LastIndex-1)) if err != nil { return nil, err } @@ -225,7 +233,7 @@ func (p *processor) GetInfoByIndex(ctx context.Context, index uint32) (*L1InfoTr } func (p *processor) getInfoByIndexWithTx(tx kv.Tx, index uint32) (*L1InfoTreeLeaf, error) { - hash, err := tx.GetOne(indexTable, uint32ToBytes(index)) + hash, err := tx.GetOne(indexTable, common.Uint32ToBytes(index)) if err != nil { return nil, err } @@ -331,7 +339,7 @@ func (p *processor) Reorg(firstReorgedBlock uint64) error { func (p *processor) deleteLeaf(tx kv.RwTx, index uint32) error { // TODO: do we need to do something with p.tree here? // Get leaf info to delete all relations - hash, err := tx.GetOne(indexTable, uint32ToBytes(index)) + hash, err := tx.GetOne(indexTable, common.Uint32ToBytes(index)) if err != nil { return err } @@ -354,7 +362,7 @@ func (p *processor) deleteLeaf(tx kv.RwTx, index uint32) error { if err := tx.Delete(rootTable, info.InfoRoot[:]); err != nil { return err } - if err := tx.Delete(indexTable, uint32ToBytes(index)); err != nil { + if err := tx.Delete(indexTable, common.Uint32ToBytes(index)); err != nil { return err } if err := tx.Delete(infoTable, hash); err != nil { @@ -365,7 +373,7 @@ func (p *processor) deleteLeaf(tx kv.RwTx, index uint32) error { // ProcessBlock process the leafs of the L1 info tree found on a block // this function can be called without leafs with the intention to track the last processed block -func (p *processor) ProcessBlock(b sync.EVMBlock) error { +func (p *processor) ProcessBlock(b sync.Block) error { tx, err := p.db.BeginRw(context.Background()) if err != nil { return err @@ -382,13 +390,13 @@ func (p *processor) ProcessBlock(b sync.EVMBlock) error { initialIndex = lastIndex + 1 } for i, e := range b.Events { - event := e.(L1InfoTreeUpdate) + event := e.(Event) leafToStore := storeLeaf{ Index: initialIndex + uint32(i), MainnetExitRoot: event.MainnetExitRoot, RollupExitRoot: event.RollupExitRoot, - ParentHash: b.ParentHash, - Timestamp: b.Timestamp, + ParentHash: event.ParentHash, + Timestamp: event.Timestamp, BlockNumber: b.Num, } if err := p.addLeaf(tx, leafToStore); err != nil { @@ -460,7 +468,7 @@ func (p *processor) addLeaf(tx kv.RwTx, leaf storeLeaf) error { return err } // store index relation - if err := tx.Put(indexTable, uint32ToBytes(leaf.Index), hash[:]); err != nil { + if err := tx.Put(indexTable, common.Uint32ToBytes(leaf.Index), hash[:]); err != nil { return err } // store root relation @@ -484,13 +492,3 @@ func uint64ToBytes(num uint64) []byte { func bytes2Uint64(key []byte) uint64 { return binary.LittleEndian.Uint64(key) } - -func uint32ToBytes(num uint32) []byte { - key := make([]byte, 4) - binary.LittleEndian.PutUint32(key, num) - return key -} - -func bytes2Uint32(key []byte) uint32 { - return binary.LittleEndian.Uint32(key) -} diff --git a/localbridgesync/downloader.go b/localbridgesync/downloader.go index 955655f1..5b6ab8f6 100644 --- a/localbridgesync/downloader.go +++ b/localbridgesync/downloader.go @@ -32,30 +32,6 @@ type EthClienter interface { bind.ContractBackend } -type Bridge struct { - LeafType uint8 - OriginNetwork uint32 - OriginAddress common.Address - DestinationNetwork uint32 - DestinationAddress common.Address - Amount *big.Int - Metadata []byte - DepositCount uint32 -} - -type Claim struct { - GlobalIndex *big.Int - OriginNetwork uint32 - OriginAddress common.Address - DestinationAddress common.Address - Amount *big.Int -} - -type BridgeEvent struct { - Bridge *Bridge - Claim *Claim -} - func buildAppender(client EthClienter, bridge common.Address) (sync.LogAppenderMap, error) { bridgeContractV1, err := polygonzkevmbridge.NewPolygonzkevmbridge(bridge, client) if err != nil { @@ -75,7 +51,7 @@ func buildAppender(client EthClienter, bridge common.Address) (sync.LogAppenderM l, err, ) } - b.Events = append(b.Events, BridgeEvent{Bridge: &Bridge{ + b.Events = append(b.Events, Event{Bridge: &Bridge{ LeafType: bridge.LeafType, OriginNetwork: bridge.OriginNetwork, OriginAddress: bridge.OriginAddress, @@ -96,7 +72,7 @@ func buildAppender(client EthClienter, bridge common.Address) (sync.LogAppenderM l, err, ) } - b.Events = append(b.Events, BridgeEvent{Claim: &Claim{ + b.Events = append(b.Events, Event{Claim: &Claim{ GlobalIndex: claim.GlobalIndex, OriginNetwork: claim.OriginNetwork, OriginAddress: claim.OriginAddress, @@ -114,7 +90,7 @@ func buildAppender(client EthClienter, bridge common.Address) (sync.LogAppenderM l, err, ) } - b.Events = append(b.Events, BridgeEvent{Claim: &Claim{ + b.Events = append(b.Events, Event{Claim: &Claim{ GlobalIndex: big.NewInt(int64(claim.Index)), OriginNetwork: claim.OriginNetwork, OriginAddress: claim.OriginAddress, diff --git a/localbridgesync/localbridgesync.go b/localbridgesync/localbridgesync.go index 6707bbad..d0617584 100644 --- a/localbridgesync/localbridgesync.go +++ b/localbridgesync/localbridgesync.go @@ -25,17 +25,31 @@ type LocalBridgeSync struct { } func New( + ctx context.Context, dbPath string, bridge common.Address, syncBlockChunkSize uint64, blockFinalityType etherman.BlockNumberFinality, rd sync.ReorgDetector, l2Client EthClienter, + initialBlock uint64, ) (*LocalBridgeSync, error) { processor, err := newProcessor(dbPath) if err != nil { return nil, err } + lastProcessedBlock, err := processor.GetLastProcessedBlock(ctx) + if err != nil { + return nil, err + } + if lastProcessedBlock < initialBlock { + err = processor.ProcessBlock(sync.Block{ + Num: initialBlock, + }) + if err != nil { + return nil, err + } + } appender, err := buildAppender(l2Client, bridge) if err != nil { diff --git a/localbridgesync/processor.go b/localbridgesync/processor.go index 443a7925..4a45c663 100644 --- a/localbridgesync/processor.go +++ b/localbridgesync/processor.go @@ -4,9 +4,11 @@ import ( "context" "encoding/json" "errors" + "math/big" "github.com/0xPolygon/cdk/common" "github.com/0xPolygon/cdk/sync" + ethCommon "github.com/ethereum/go-ethereum/common" "github.com/ledgerwatch/erigon-lib/kv" "github.com/ledgerwatch/erigon-lib/kv/mdbx" ) @@ -21,6 +23,30 @@ var ( lastBlokcKey = []byte("lb") ) +type Bridge struct { + LeafType uint8 + OriginNetwork uint32 + OriginAddress ethCommon.Address + DestinationNetwork uint32 + DestinationAddress ethCommon.Address + Amount *big.Int + Metadata []byte + DepositCount uint32 +} + +type Claim struct { + GlobalIndex *big.Int + OriginNetwork uint32 + OriginAddress ethCommon.Address + DestinationAddress ethCommon.Address + Amount *big.Int +} + +type Event struct { + Bridge *Bridge + Claim *Claim +} + type processor struct { db kv.RwDB } @@ -49,8 +75,8 @@ func newProcessor(dbPath string) (*processor, error) { // If toBlock has not been porcessed yet, ErrBlockNotProcessed will be returned func (p *processor) GetClaimsAndBridges( ctx context.Context, fromBlock, toBlock uint64, -) ([]BridgeEvent, error) { - events := []BridgeEvent{} +) ([]Event, error) { + events := []Event{} tx, err := p.db.BeginRo(ctx) if err != nil { @@ -70,14 +96,14 @@ func (p *processor) GetClaimsAndBridges( } defer c.Close() - for k, v, err := c.Seek(common.BlockNum2Bytes(fromBlock)); k != nil; k, v, err = c.Next() { + for k, v, err := c.Seek(common.Uint64To2Bytes(fromBlock)); k != nil; k, v, err = c.Next() { if err != nil { return nil, err } - if common.Bytes2BlockNum(k) > toBlock { + if common.BytesToUint64(k) > toBlock { break } - blockEvents := []BridgeEvent{} + blockEvents := []Event{} err := json.Unmarshal(v, &blockEvents) if err != nil { return nil, err @@ -103,7 +129,7 @@ func (p *processor) getLastProcessedBlockWithTx(tx kv.Tx) (uint64, error) { } else if blockNumBytes == nil { return 0, nil } else { - return common.Bytes2BlockNum(blockNumBytes), nil + return common.BytesToUint64(blockNumBytes), nil } } @@ -117,7 +143,7 @@ func (p *processor) Reorg(firstReorgedBlock uint64) error { return err } defer c.Close() - firstKey := common.BlockNum2Bytes(firstReorgedBlock) + firstKey := common.Uint64To2Bytes(firstReorgedBlock) for k, _, err := c.Seek(firstKey); k != nil; k, _, err = c.Next() { if err != nil { tx.Rollback() @@ -135,22 +161,22 @@ func (p *processor) Reorg(firstReorgedBlock uint64) error { return tx.Commit() } -func (p *processor) ProcessBlock(block sync.EVMBlock) error { +func (p *processor) ProcessBlock(block sync.Block) error { tx, err := p.db.BeginRw(context.Background()) if err != nil { return err } if len(block.Events) > 0 { - events := []BridgeEvent{} + events := []Event{} for _, e := range block.Events { - events = append(events, e.(BridgeEvent)) + events = append(events, e.(Event)) } value, err := json.Marshal(events) if err != nil { tx.Rollback() return err } - if err := tx.Put(eventsTable, common.BlockNum2Bytes(block.Num), value); err != nil { + if err := tx.Put(eventsTable, common.Uint64To2Bytes(block.Num), value); err != nil { tx.Rollback() return err } @@ -163,6 +189,6 @@ func (p *processor) ProcessBlock(block sync.EVMBlock) error { } func (p *processor) updateLastProcessedBlock(tx kv.RwTx, blockNum uint64) error { - blockNumBytes := common.BlockNum2Bytes(blockNum) + blockNumBytes := common.Uint64To2Bytes(blockNum) return tx.Put(lastBlockTable, lastBlokcKey, blockNumBytes) } diff --git a/localbridgesync/processor_test.go b/localbridgesync/processor_test.go index a7835256..dbf0d74c 100644 --- a/localbridgesync/processor_test.go +++ b/localbridgesync/processor_test.go @@ -121,7 +121,7 @@ func TestProceessor(t *testing.T) { ctx: context.Background(), fromBlock: 2, toBlock: 2, - expectedEvents: []BridgeEvent{}, + expectedEvents: []Event{}, expectedErr: nil, }, &getClaimsAndBridgesAction{ @@ -241,13 +241,10 @@ func TestProceessor(t *testing.T) { // blocks var ( - block1 = sync.EVMBlock{ - EVMBlockHeader: sync.EVMBlockHeader{ - Num: 1, - Hash: common.HexToHash("01"), - }, + block1 = sync.Block{ + Num: 1, Events: []interface{}{ - BridgeEvent{Bridge: &Bridge{ + Event{Bridge: &Bridge{ LeafType: 1, OriginNetwork: 1, OriginAddress: common.HexToAddress("01"), @@ -257,7 +254,7 @@ var ( Metadata: common.Hex2Bytes("01"), DepositCount: 1, }}, - BridgeEvent{Claim: &Claim{ + Event{Claim: &Claim{ GlobalIndex: big.NewInt(1), OriginNetwork: 1, OriginAddress: common.HexToAddress("01"), @@ -266,13 +263,10 @@ var ( }}, }, } - block3 = sync.EVMBlock{ - EVMBlockHeader: sync.EVMBlockHeader{ - Num: 3, - Hash: common.HexToHash("02"), - }, + block3 = sync.Block{ + Num: 3, Events: []interface{}{ - BridgeEvent{Bridge: &Bridge{ + Event{Bridge: &Bridge{ LeafType: 2, OriginNetwork: 2, OriginAddress: common.HexToAddress("02"), @@ -282,7 +276,7 @@ var ( Metadata: common.Hex2Bytes("02"), DepositCount: 2, }}, - BridgeEvent{Bridge: &Bridge{ + Event{Bridge: &Bridge{ LeafType: 3, OriginNetwork: 3, OriginAddress: common.HexToAddress("03"), @@ -294,27 +288,21 @@ var ( }}, }, } - block4 = sync.EVMBlock{ - EVMBlockHeader: sync.EVMBlockHeader{ - Num: 4, - Hash: common.HexToHash("03"), - }, + block4 = sync.Block{ + Num: 4, Events: []interface{}{}, } - block5 = sync.EVMBlock{ - EVMBlockHeader: sync.EVMBlockHeader{ - Num: 5, - Hash: common.HexToHash("04"), - }, + block5 = sync.Block{ + Num: 5, Events: []interface{}{ - BridgeEvent{Claim: &Claim{ + Event{Claim: &Claim{ GlobalIndex: big.NewInt(4), OriginNetwork: 4, OriginAddress: common.HexToAddress("04"), DestinationAddress: common.HexToAddress("04"), Amount: big.NewInt(4), }}, - BridgeEvent{Claim: &Claim{ + Event{Claim: &Claim{ GlobalIndex: big.NewInt(5), OriginNetwork: 5, OriginAddress: common.HexToAddress("05"), @@ -341,7 +329,7 @@ type getClaimsAndBridgesAction struct { ctx context.Context fromBlock uint64 toBlock uint64 - expectedEvents []BridgeEvent + expectedEvents []Event expectedErr error } @@ -410,7 +398,7 @@ func (a *reorgAction) execute(t *testing.T) { type processBlockAction struct { p *processor description string - block sync.EVMBlock + block sync.Block expectedErr error } @@ -427,10 +415,10 @@ func (a *processBlockAction) execute(t *testing.T) { require.Equal(t, a.expectedErr, actualErr) } -func eventsToBridgeEvents(events []interface{}) []BridgeEvent { - bridgeEvents := []BridgeEvent{} +func eventsToBridgeEvents(events []interface{}) []Event { + bridgeEvents := []Event{} for _, event := range events { - bridgeEvents = append(bridgeEvents, event.(BridgeEvent)) + bridgeEvents = append(bridgeEvents, event.(Event)) } return bridgeEvents } diff --git a/sync/driver.go b/sync/driver.go new file mode 100644 index 00000000..bd066ba1 --- /dev/null +++ b/sync/driver.go @@ -0,0 +1,14 @@ +package sync + +import "context" + +type Block struct { + Num uint64 + Events []interface{} +} + +type ProcessorInterface interface { + GetLastProcessedBlock(ctx context.Context) (uint64, error) + ProcessBlock(block Block) error + Reorg(firstReorgedBlock uint64) error +} diff --git a/sync/evmdriver.go b/sync/evmdriver.go index 0363e00c..a30b96d6 100644 --- a/sync/evmdriver.go +++ b/sync/evmdriver.go @@ -24,7 +24,7 @@ type EVMDriver struct { type processorInterface interface { GetLastProcessedBlock(ctx context.Context) (uint64, error) - ProcessBlock(block EVMBlock) error + ProcessBlock(block Block) error Reorg(firstReorgedBlock uint64) error } @@ -105,7 +105,11 @@ func (d *EVMDriver) handleNewBlock(ctx context.Context, b EVMBlock) { } attempts = 0 for { - err := d.processor.ProcessBlock(b) + blockToProcess := Block{ + Num: b.Num, + Events: b.Events, + } + err := d.processor.ProcessBlock(blockToProcess) if err != nil { attempts++ log.Errorf("error processing events for blcok %d, err: ", b.Num, err) diff --git a/sync/evmdriver_test.go b/sync/evmdriver_test.go index 1f063cdb..502722f6 100644 --- a/sync/evmdriver_test.go +++ b/sync/evmdriver_test.go @@ -78,11 +78,11 @@ func TestSync(t *testing.T) { Return(uint64(3), nil) rdm.On("AddBlockToTrack", ctx, reorgDetectorID, expectedBlock1.Num, expectedBlock1.Hash). Return(nil) - pm.On("ProcessBlock", expectedBlock1). + pm.On("ProcessBlock", Block{Num: expectedBlock1.Num, Events: expectedBlock1.Events}). Return(nil) rdm.On("AddBlockToTrack", ctx, reorgDetectorID, expectedBlock2.Num, expectedBlock2.Hash). Return(nil) - pm.On("ProcessBlock", expectedBlock2). + pm.On("ProcessBlock", Block{Num: expectedBlock2.Num, Events: expectedBlock2.Events}). Return(nil) go driver.Sync(ctx) time.Sleep(time.Millisecond * 200) // time to download expectedBlock1 @@ -126,7 +126,7 @@ func TestHandleNewBlock(t *testing.T) { rdm. On("AddBlockToTrack", ctx, reorgDetectorID, b1.Num, b1.Hash). Return(nil) - pm.On("ProcessBlock", b1). + pm.On("ProcessBlock", Block{Num: b1.Num, Events: b1.Events}). Return(nil) driver.handleNewBlock(ctx, b1) @@ -143,7 +143,7 @@ func TestHandleNewBlock(t *testing.T) { rdm. On("AddBlockToTrack", ctx, reorgDetectorID, b2.Num, b2.Hash). Return(nil).Once() - pm.On("ProcessBlock", b2). + pm.On("ProcessBlock", Block{Num: b2.Num, Events: b2.Events}). Return(nil) driver.handleNewBlock(ctx, b2) @@ -157,9 +157,9 @@ func TestHandleNewBlock(t *testing.T) { rdm. On("AddBlockToTrack", ctx, reorgDetectorID, b3.Num, b3.Hash). Return(nil) - pm.On("ProcessBlock", b3). + pm.On("ProcessBlock", Block{Num: b3.Num, Events: b3.Events}). Return(errors.New("foo")).Once() - pm.On("ProcessBlock", b3). + pm.On("ProcessBlock", Block{Num: b3.Num, Events: b3.Events}). Return(nil).Once() driver.handleNewBlock(ctx, b3) @@ -182,7 +182,7 @@ func TestHandleReorg(t *testing.T) { _, cancel := context.WithCancel(ctx) downloadCh := make(chan EVMBlock) firstReorgedBlock := uint64(5) - pm.On("reorg", firstReorgedBlock).Return(nil) + pm.On("Reorg", firstReorgedBlock).Return(nil) go driver.handleReorg(cancel, downloadCh, firstReorgedBlock) close(downloadCh) done := <-reorgProcessed @@ -192,7 +192,7 @@ func TestHandleReorg(t *testing.T) { _, cancel = context.WithCancel(ctx) downloadCh = make(chan EVMBlock) firstReorgedBlock = uint64(6) - pm.On("reorg", firstReorgedBlock).Return(nil) + pm.On("Reorg", firstReorgedBlock).Return(nil) go driver.handleReorg(cancel, downloadCh, firstReorgedBlock) downloadCh <- EVMBlock{} downloadCh <- EVMBlock{} @@ -205,9 +205,9 @@ func TestHandleReorg(t *testing.T) { _, cancel = context.WithCancel(ctx) downloadCh = make(chan EVMBlock) firstReorgedBlock = uint64(7) - pm.On("reorg", firstReorgedBlock).Return(errors.New("foo")).Once() - pm.On("reorg", firstReorgedBlock).Return(errors.New("foo")).Once() - pm.On("reorg", firstReorgedBlock).Return(nil).Once() + pm.On("Reorg", firstReorgedBlock).Return(errors.New("foo")).Once() + pm.On("Reorg", firstReorgedBlock).Return(errors.New("foo")).Once() + pm.On("Reorg", firstReorgedBlock).Return(nil).Once() go driver.handleReorg(cancel, downloadCh, firstReorgedBlock) close(downloadCh) done = <-reorgProcessed diff --git a/sync/mock_processor_test.go b/sync/mock_processor_test.go index f0959b29..d2c3e299 100644 --- a/sync/mock_processor_test.go +++ b/sync/mock_processor_test.go @@ -38,11 +38,11 @@ func (_m *ProcessorMock) GetLastProcessedBlock(ctx context.Context) (uint64, err } // ProcessBlock provides a mock function with given fields: block -func (_m *ProcessorMock) ProcessBlock(block EVMBlock) error { +func (_m *ProcessorMock) ProcessBlock(block Block) error { ret := _m.Called(block) var r0 error - if rf, ok := ret.Get(0).(func(EVMBlock) error); ok { + if rf, ok := ret.Get(0).(func(Block) error); ok { r0 = rf(block) } else { r0 = ret.Error(0) From 80157a440a111c2c32de9c906897730ee0fb2bff Mon Sep 17 00:00:00 2001 From: Arnau Date: Fri, 26 Jul 2024 12:06:30 +0200 Subject: [PATCH 07/18] Add CLI for aggOracle --- aggoracle/chaingersender/evm.go | 21 +- aggoracle/config.go | 24 ++ aggoracle/e2e_test.go | 2 +- cmd/main.go | 4 +- cmd/run.go | 97 +++++++++ config/config.go | 9 + l1infotreesync/e2e_test.go | 2 +- l1infotreesync/l1infotreesync.go | 14 +- l1infotreesync/processor.go | 4 +- l1infotreesync/processor_test.go | 362 +------------------------------ localbridgesync/e2e_test.go | 3 + reorgdetector/reorgdetector.go | 4 + 12 files changed, 174 insertions(+), 372 deletions(-) create mode 100644 aggoracle/config.go create mode 100644 localbridgesync/e2e_test.go diff --git a/aggoracle/chaingersender/evm.go b/aggoracle/chaingersender/evm.go index b3b6e405..42cd49a4 100644 --- a/aggoracle/chaingersender/evm.go +++ b/aggoracle/chaingersender/evm.go @@ -7,6 +7,7 @@ import ( "time" "github.com/0xPolygon/cdk-contracts-tooling/contracts/manual/pessimisticglobalexitroot" + cfgTypes "github.com/0xPolygon/cdk/config/types" "github.com/0xPolygon/cdk/log" "github.com/0xPolygonHermez/zkevm-ethtx-manager/ethtxmanager" "github.com/ethereum/go-ethereum" @@ -39,22 +40,32 @@ type EVMChainGERSender struct { waitPeriodMonitorTx time.Duration } +type EVMConfig struct { + GlobalExitRootL2 common.Address `mapstructure:"GlobalExitRootL2"` + URLRPCL2 string `mapstructure:"URLRPCL2"` + ChainIDL2 uint64 `mapstructure:"ChainIDL2"` + GasOffset uint64 `mapstructure:"GasOffset"` + WaitPeriodMonitorTx cfgTypes.Duration `mapstructure:"WaitPeriodMonitorTx"` + SenderAddr common.Address `mapstructure:"SenderAddr"` + EthTxManager ethtxmanager.Config `mapstructure:"EthTxManager"` +} + func NewEVMChainGERSender( - globalExitRoot, sender common.Address, - client EthClienter, + l2GlobalExitRoot, sender common.Address, + l2Client EthClienter, ethTxMan EthTxManager, gasOffset uint64, waitPeriodMonitorTx time.Duration, ) (*EVMChainGERSender, error) { - gerContract, err := pessimisticglobalexitroot.NewPessimisticglobalexitroot(globalExitRoot, client) + gerContract, err := pessimisticglobalexitroot.NewPessimisticglobalexitroot(l2GlobalExitRoot, l2Client) if err != nil { return nil, err } return &EVMChainGERSender{ gerContract: gerContract, - gerAddr: globalExitRoot, + gerAddr: l2GlobalExitRoot, sender: sender, - client: client, + client: l2Client, ethTxMan: ethTxMan, gasOffset: gasOffset, waitPeriodMonitorTx: waitPeriodMonitorTx, diff --git a/aggoracle/config.go b/aggoracle/config.go new file mode 100644 index 00000000..d78747da --- /dev/null +++ b/aggoracle/config.go @@ -0,0 +1,24 @@ +package aggoracle + +import ( + "github.com/0xPolygon/cdk/aggoracle/chaingersender" + "github.com/0xPolygon/cdk/config/types" +) + +type TargetChainType string + +const ( + EVMChain TargetChainType = "EVM" +) + +var ( + SupportedChainTypes = []TargetChainType{EVMChain} +) + +type Config struct { + TargetChainType TargetChainType `mapstructure:"TargetChainType"` + EVMSender chaingersender.EVMConfig `mapstructure:"EVMSender"` + URLRPCL1 string `mapstructure:"URLRPCL1"` + BlockFinality string `jsonschema:"enum=latest,enum=safe, enum=pending, enum=finalized" mapstructure:"BlockFinality"` + WaitPeriodNextGER types.Duration `mapstructure:"WaitPeriodNextGER"` +} diff --git a/aggoracle/e2e_test.go b/aggoracle/e2e_test.go index 18b7572d..ad1ff9c3 100644 --- a/aggoracle/e2e_test.go +++ b/aggoracle/e2e_test.go @@ -59,7 +59,7 @@ func commonSetup(t *testing.T) ( require.NoError(t, err) // Syncer dbPathSyncer := t.TempDir() - syncer, err := l1infotreesync.New(ctx, dbPathSyncer, gerL1Addr, 10, etherman.LatestBlock, reorg, l1Client.Client(), 32, time.Millisecond, 0) + syncer, err := l1infotreesync.New(ctx, dbPathSyncer, gerL1Addr, 10, etherman.LatestBlock, reorg, l1Client.Client(), time.Millisecond, 0) require.NoError(t, err) go syncer.Start(ctx) diff --git a/cmd/main.go b/cmd/main.go index ce319729..a13f43e1 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -16,6 +16,8 @@ const ( SEQUENCE_SENDER = "sequence-sender" // AGGREGATOR name to identify the aggregator component AGGREGATOR = "aggregator" + // AGGORACLE name to identify the aggoracle component + AGGORACLE = "aggoracle" ) const ( @@ -47,7 +49,7 @@ var ( Aliases: []string{"co"}, Usage: "List of components to run", Required: false, - Value: cli.NewStringSlice(SEQUENCE_SENDER, AGGREGATOR), + Value: cli.NewStringSlice(SEQUENCE_SENDER, AGGREGATOR, AGGORACLE), } ) diff --git a/cmd/run.go b/cmd/run.go index 15d24c29..57fc2e4d 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -10,6 +10,8 @@ import ( zkevm "github.com/0xPolygon/cdk" dataCommitteeClient "github.com/0xPolygon/cdk-data-availability/client" + "github.com/0xPolygon/cdk/aggoracle" + "github.com/0xPolygon/cdk/aggoracle/chaingersender" "github.com/0xPolygon/cdk/aggregator" "github.com/0xPolygon/cdk/aggregator/db" "github.com/0xPolygon/cdk/config" @@ -18,7 +20,9 @@ import ( "github.com/0xPolygon/cdk/etherman" ethermanconfig "github.com/0xPolygon/cdk/etherman/config" "github.com/0xPolygon/cdk/etherman/contracts" + "github.com/0xPolygon/cdk/l1infotreesync" "github.com/0xPolygon/cdk/log" + "github.com/0xPolygon/cdk/reorgdetector" "github.com/0xPolygon/cdk/sequencesender" "github.com/0xPolygon/cdk/sequencesender/txbuilder" "github.com/0xPolygon/cdk/state" @@ -26,6 +30,9 @@ import ( "github.com/0xPolygon/cdk/translator" ethtxman "github.com/0xPolygonHermez/zkevm-ethtx-manager/etherman" "github.com/0xPolygonHermez/zkevm-ethtx-manager/etherman/etherscan" + "github.com/0xPolygonHermez/zkevm-ethtx-manager/ethtxmanager" + ethtxlog "github.com/0xPolygonHermez/zkevm-ethtx-manager/log" + "github.com/ethereum/go-ethereum/ethclient" "github.com/jackc/pgx/v4/pgxpool" "github.com/urfave/cli/v2" ) @@ -63,6 +70,16 @@ func start(cliCtx *cli.Context) error { log.Fatal(err) } }() + case AGGORACLE: + l1Client, err := ethclient.Dial(c.AggOracle.URLRPCL1) + if err != nil { + log.Fatal(err) + } + reorgDetector := newReorgDetectorL1(cliCtx.Context, *c, l1Client) + syncer := newL1InfoTreeSyncer(cliCtx.Context, *c, l1Client, reorgDetector) + go syncer.Start(cliCtx.Context) + aggOracle := createAggoracle(*c, l1Client, syncer) + go aggOracle.Start(cliCtx.Context) } } @@ -180,6 +197,51 @@ func newTxBuilder(cfg config.Config, ethman *etherman.Client) (txbuilder.TxBuild return txBuilder, err } +func createAggoracle(cfg config.Config, l1Client *ethclient.Client, syncer *l1infotreesync.L1InfoTreeSync) *aggoracle.AggOracle { + var sender aggoracle.ChainSender + switch cfg.AggOracle.TargetChainType { + case aggoracle.EVMChain: + cfg.AggOracle.EVMSender.EthTxManager.Log = ethtxlog.Config{ + Environment: ethtxlog.LogEnvironment(cfg.Log.Environment), + Level: cfg.Log.Level, + Outputs: cfg.Log.Outputs, + } + ethTxManager, err := ethtxmanager.New(cfg.AggOracle.EVMSender.EthTxManager) + l2CLient, err := ethclient.Dial(cfg.AggOracle.EVMSender.URLRPCL2) + if err != nil { + log.Fatal(err) + } + sender, err = chaingersender.NewEVMChainGERSender( + cfg.AggOracle.EVMSender.GlobalExitRootL2, + cfg.AggOracle.EVMSender.SenderAddr, + l2CLient, + ethTxManager, + cfg.AggOracle.EVMSender.GasOffset, + cfg.AggOracle.EVMSender.WaitPeriodMonitorTx.Duration, + ) + if err != nil { + log.Fatal(err) + } + default: + log.Fatalf( + "Unsupported chaintype %s. Supported values: %v", + cfg.AggOracle.TargetChainType, aggoracle.SupportedChainTypes, + ) + } + aggOracle, err := aggoracle.New( + sender, + l1Client, + syncer, + etherman.BlockNumberFinality(cfg.AggOracle.BlockFinality), + cfg.AggOracle.WaitPeriodNextGER.Duration, + ) + if err != nil { + log.Fatal(err) + } + + return aggOracle +} + func newDataAvailability(c config.Config, etherman *etherman.Client) (*dataavailability.DataAvailability, error) { if !c.Common.IsValidiumMode { return nil, nil @@ -292,3 +354,38 @@ func newState(c *config.Config, l2ChainID uint64, sqlDB *pgxpool.Pool) *state.St st := state.NewState(stateCfg, stateDb) return st } + +func newReorgDetectorL1( + ctx context.Context, + cfg config.Config, + l1Client *ethclient.Client, +) *reorgdetector.ReorgDetector { + rd, err := reorgdetector.New(ctx, l1Client, cfg.ReorgDetectorL1.DBPath) + if err != nil { + log.Fatal(err) + } + return rd +} + +func newL1InfoTreeSyncer( + ctx context.Context, + cfg config.Config, + l1Client *ethclient.Client, + reorgDetector *reorgdetector.ReorgDetector, +) *l1infotreesync.L1InfoTreeSync { + syncer, err := l1infotreesync.New( + ctx, + cfg.L1InfoTreeSync.DBPath, + cfg.L1InfoTreeSync.GlobalExitRootAddr, + cfg.L1InfoTreeSync.SyncBlockChunkSize, + etherman.BlockNumberFinality(cfg.L1InfoTreeSync.BlockFinality), + reorgDetector, + l1Client, + cfg.L1InfoTreeSync.WaitForNewBlocksPeriod.Duration, + cfg.L1InfoTreeSync.InitialBlock, + ) + if err != nil { + log.Fatal(err) + } + return syncer +} diff --git a/config/config.go b/config/config.go index 02ede0fb..ed452417 100644 --- a/config/config.go +++ b/config/config.go @@ -5,10 +5,13 @@ import ( "path/filepath" "strings" + "github.com/0xPolygon/cdk/aggoracle" "github.com/0xPolygon/cdk/aggregator" "github.com/0xPolygon/cdk/common" ethermanconfig "github.com/0xPolygon/cdk/etherman/config" + "github.com/0xPolygon/cdk/l1infotreesync" "github.com/0xPolygon/cdk/log" + "github.com/0xPolygon/cdk/reorgdetector" "github.com/0xPolygon/cdk/sequencesender" "github.com/0xPolygonHermez/zkevm-ethtx-manager/ethtxmanager" "github.com/mitchellh/mapstructure" @@ -70,6 +73,12 @@ type Config struct { // Common Config that affects all the services Common common.Config + // Configuration of the reorg detector service to be used for the L1 + ReorgDetectorL1 reorgdetector.Config + // Configuration of the aggOracle service + AggOracle aggoracle.Config + // Configuration of the L1 Info Treee Sync service + L1InfoTreeSync l1infotreesync.Config } // Default parses the default configuration values. diff --git a/l1infotreesync/e2e_test.go b/l1infotreesync/e2e_test.go index 81be3d9a..35958f08 100644 --- a/l1infotreesync/e2e_test.go +++ b/l1infotreesync/e2e_test.go @@ -54,7 +54,7 @@ func TestE2E(t *testing.T) { rdm.On("AddBlockToTrack", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) client, gerAddr, gerSc, err := newSimulatedClient(auth) require.NoError(t, err) - syncer, err := New(ctx, dbPath, gerAddr, 10, etherman.LatestBlock, rdm, client.Client(), 32, time.Millisecond, 0) + syncer, err := New(ctx, dbPath, gerAddr, 10, etherman.LatestBlock, rdm, client.Client(), time.Millisecond, 0) require.NoError(t, err) go syncer.Start(ctx) diff --git a/l1infotreesync/l1infotreesync.go b/l1infotreesync/l1infotreesync.go index 695035f3..6c8390ef 100644 --- a/l1infotreesync/l1infotreesync.go +++ b/l1infotreesync/l1infotreesync.go @@ -4,6 +4,7 @@ import ( "context" "time" + "github.com/0xPolygon/cdk/config/types" "github.com/0xPolygon/cdk/etherman" "github.com/0xPolygon/cdk/sync" "github.com/ethereum/go-ethereum/common" @@ -19,6 +20,16 @@ var ( maxRetryAttemptsAfterError = 5 ) +type Config struct { + DBPath string `mapstructure:"DBPath"` + GlobalExitRootAddr common.Address `mapstructure:"GlobalExitRootAddr"` + SyncBlockChunkSize uint64 `mapstructure:"SyncBlockChunkSize"` + BlockFinality string `jsonschema:"enum=latest,enum=safe, enum=pending, enum=finalized" mapstructure:"BlockFinality"` + URLRPCL1 string `mapstructure:"URLRPCL1"` + WaitForNewBlocksPeriod types.Duration `mapstructure:"WaitForNewBlocksPeriod"` + InitialBlock uint64 `mapstructure:"InitialBlock"` +} + type L1InfoTreeSync struct { processor *processor driver *sync.EVMDriver @@ -32,11 +43,10 @@ func New( blockFinalityType etherman.BlockNumberFinality, rd sync.ReorgDetector, l1Client EthClienter, - treeHeight uint8, waitForNewBlocksPeriod time.Duration, initialBlock uint64, ) (*L1InfoTreeSync, error) { - processor, err := newProcessor(ctx, dbPath, treeHeight) + processor, err := newProcessor(ctx, dbPath) if err != nil { return nil, err } diff --git a/l1infotreesync/processor.go b/l1infotreesync/processor.go index 8fea2d60..fcb8b028 100644 --- a/l1infotreesync/processor.go +++ b/l1infotreesync/processor.go @@ -21,6 +21,8 @@ const ( infoTable = "l1infotreesync-info" blockTable = "l1infotreesync-block" lastBlockTable = "l1infotreesync-lastBlock" + + treeHeight uint8 = 32 ) var ( @@ -88,7 +90,7 @@ func tableCfgFunc(defaultBuckets kv.TableCfg) kv.TableCfg { } } -func newProcessor(ctx context.Context, dbPath string, treeHeight uint8) (*processor, error) { +func newProcessor(ctx context.Context, dbPath string) (*processor, error) { db, err := mdbx.NewMDBX(nil). Path(dbPath). WithTableCfg(tableCfgFunc). diff --git a/l1infotreesync/processor_test.go b/l1infotreesync/processor_test.go index b6f6c942..01550f31 100644 --- a/l1infotreesync/processor_test.go +++ b/l1infotreesync/processor_test.go @@ -1,363 +1,3 @@ package l1infotreesync -// func TestProceessor(t *testing.T) { -// path := t.TempDir() -// ctx := context.Background() -// p, err := newProcessor(ctx, path, 32) -// require.NoError(t, err) -// actions := []processAction{ -// // processed: ~ -// &getLastProcessedBlockAction{ -// p: p, -// description: "on an empty processor", -// ctx: context.Background(), -// expectedLastProcessedBlock: 0, -// expectedErr: nil, -// }, -// &reorgAction{ -// p: p, -// description: "on an empty processor: firstReorgedBlock = 0", -// firstReorgedBlock: 0, -// expectedErr: nil, -// }, -// &reorgAction{ -// p: p, -// description: "on an empty processor: firstReorgedBlock = 1", -// firstReorgedBlock: 1, -// expectedErr: nil, -// }, -// &getClaimsAndBridgesAction{ -// p: p, -// description: "on an empty processor", -// ctx: context.Background(), -// fromBlock: 0, -// toBlock: 2, -// expectedEvents: nil, -// expectedErr: ErrBlockNotProcessed, -// }, -// &storeL1InfoTreeUpdatesAction{ -// p: p, -// description: "block1", -// b: block1, -// expectedErr: nil, -// }, -// // processed: block1 -// &getLastProcessedBlockAction{ -// p: p, -// description: "after block1", -// ctx: context.Background(), -// expectedLastProcessedBlock: 1, -// expectedErr: nil, -// }, -// &getClaimsAndBridgesAction{ -// p: p, -// description: "after block1: range 0, 2", -// ctx: context.Background(), -// fromBlock: 0, -// toBlock: 2, -// expectedEvents: nil, -// expectedErr: ErrBlockNotProcessed, -// }, -// &getClaimsAndBridgesAction{ -// p: p, -// description: "after block1: range 1, 1", -// ctx: context.Background(), -// fromBlock: 1, -// toBlock: 1, -// expectedEvents: block1.Events, -// expectedErr: nil, -// }, -// &reorgAction{ -// p: p, -// description: "after block1", -// firstReorgedBlock: 1, -// expectedErr: nil, -// }, -// // processed: ~ -// &getClaimsAndBridgesAction{ -// p: p, -// description: "after block1 reorged", -// ctx: context.Background(), -// fromBlock: 0, -// toBlock: 2, -// expectedEvents: nil, -// expectedErr: ErrBlockNotProcessed, -// }, -// &storeL1InfoTreeUpdatesAction{ -// p: p, -// description: "block1 (after it's reorged)", -// b: block1, -// expectedErr: nil, -// }, -// // processed: block3 -// &storeL1InfoTreeUpdatesAction{ -// p: p, -// description: "block3", -// b: block3, -// expectedErr: nil, -// }, -// // processed: block1, block3 -// &getLastProcessedBlockAction{ -// p: p, -// description: "after block3", -// ctx: context.Background(), -// expectedLastProcessedBlock: 3, -// expectedErr: nil, -// }, -// &getClaimsAndBridgesAction{ -// p: p, -// description: "after block3: range 2, 2", -// ctx: context.Background(), -// fromBlock: 2, -// toBlock: 2, -// expectedEvents: []L1InfoTreeUpdate{}, -// expectedErr: nil, -// }, -// &getClaimsAndBridgesAction{ -// p: p, -// description: "after block3: range 1, 3", -// ctx: context.Background(), -// fromBlock: 1, -// toBlock: 3, -// expectedEvents: append(block1.Events, block3.Events...), -// expectedErr: nil, -// }, -// &reorgAction{ -// p: p, -// description: "after block3, with value 3", -// firstReorgedBlock: 3, -// expectedErr: nil, -// }, -// // processed: block1 -// &getLastProcessedBlockAction{ -// p: p, -// description: "after block3 reorged", -// ctx: context.Background(), -// expectedLastProcessedBlock: 2, -// expectedErr: nil, -// }, -// &reorgAction{ -// p: p, -// description: "after block3, with value 2", -// firstReorgedBlock: 2, -// expectedErr: nil, -// }, -// &getLastProcessedBlockAction{ -// p: p, -// description: "after block2 reorged", -// ctx: context.Background(), -// expectedLastProcessedBlock: 1, -// expectedErr: nil, -// }, -// &storeL1InfoTreeUpdatesAction{ -// p: p, -// description: "block3 after reorg", -// b: block3, -// expectedErr: nil, -// }, -// // processed: block1, block3 -// &storeL1InfoTreeUpdatesAction{ -// p: p, -// description: "block4", -// b: block4, -// expectedErr: nil, -// }, -// // processed: block1, block3, block4 -// &storeL1InfoTreeUpdatesAction{ -// p: p, -// description: "block5", -// b: block5, -// expectedErr: nil, -// }, -// // processed: block1, block3, block4, block5 -// &getLastProcessedBlockAction{ -// p: p, -// description: "after block5", -// ctx: context.Background(), -// expectedLastProcessedBlock: 5, -// expectedErr: nil, -// }, -// &getClaimsAndBridgesAction{ -// p: p, -// description: "after block5: range 1, 3", -// ctx: context.Background(), -// fromBlock: 1, -// toBlock: 3, -// expectedEvents: append(block1.Events, block3.Events...), -// expectedErr: nil, -// }, -// &getClaimsAndBridgesAction{ -// p: p, -// description: "after block5: range 4, 5", -// ctx: context.Background(), -// fromBlock: 4, -// toBlock: 5, -// expectedEvents: append(block4.Events, block5.Events...), -// expectedErr: nil, -// }, -// &getClaimsAndBridgesAction{ -// p: p, -// description: "after block5: range 0, 5", -// ctx: context.Background(), -// fromBlock: 0, -// toBlock: 5, -// expectedEvents: slices.Concat( -// block1.Events, -// block3.Events, -// block4.Events, -// block5.Events, -// ), -// expectedErr: nil, -// }, -// } - -// for _, a := range actions { -// t.Run(fmt.Sprintf("%s: %s", a.method(), a.desc()), a.execute) -// } -// } - -// // BOILERPLATE - -// // blocks - -// var ( -// block1 = block{ -// blockHeader: blockHeader{ -// Num: 1, -// Hash: common.HexToHash("01"), -// }, -// Events: []L1InfoTreeUpdate{ -// {RollupExitRoot: common.HexToHash("01")}, -// {MainnetExitRoot: common.HexToHash("01")}, -// }, -// } -// block3 = block{ -// blockHeader: blockHeader{ -// Num: 3, -// Hash: common.HexToHash("02"), -// }, -// Events: []L1InfoTreeUpdate{ -// {RollupExitRoot: common.HexToHash("02"), MainnetExitRoot: common.HexToHash("02")}, -// }, -// } -// block4 = block{ -// blockHeader: blockHeader{ -// Num: 4, -// Hash: common.HexToHash("03"), -// }, -// Events: []L1InfoTreeUpdate{}, -// } -// block5 = block{ -// blockHeader: blockHeader{ -// Num: 5, -// Hash: common.HexToHash("04"), -// }, -// Events: []L1InfoTreeUpdate{ -// {RollupExitRoot: common.HexToHash("04")}, -// {MainnetExitRoot: common.HexToHash("05")}, -// }, -// } -// ) - -// // actions - -// type processAction interface { -// method() string -// desc() string -// execute(t *testing.T) -// } - -// // GetClaimsAndBridges - -// type getClaimsAndBridgesAction struct { -// p *processor -// description string -// ctx context.Context -// fromBlock uint64 -// toBlock uint64 -// expectedEvents []L1InfoTreeUpdate -// expectedErr error -// } - -// func (a *getClaimsAndBridgesAction) method() string { -// return "GetClaimsAndBridges" -// } - -// func (a *getClaimsAndBridgesAction) desc() string { -// return a.description -// } - -// func (a *getClaimsAndBridgesAction) execute(t *testing.T) { -// // TODO: add relevant getters -// // actualEvents, actualErr := a.p.GetClaimsAndBridges(a.ctx, a.fromBlock, a.toBlock) -// // require.Equal(t, a.expectedEvents, actualEvents) -// // require.Equal(t, a.expectedErr, actualErr) -// } - -// // getLastProcessedBlock - -// type getLastProcessedBlockAction struct { -// p *processor -// description string -// ctx context.Context -// expectedLastProcessedBlock uint64 -// expectedErr error -// } - -// func (a *getLastProcessedBlockAction) method() string { -// return "getLastProcessedBlock" -// } - -// func (a *getLastProcessedBlockAction) desc() string { -// return a.description -// } - -// func (a *getLastProcessedBlockAction) execute(t *testing.T) { -// actualLastProcessedBlock, actualErr := a.p.getLastProcessedBlock(a.ctx) -// require.Equal(t, a.expectedLastProcessedBlock, actualLastProcessedBlock) -// require.Equal(t, a.expectedErr, actualErr) -// } - -// // reorg - -// type reorgAction struct { -// p *processor -// description string -// firstReorgedBlock uint64 -// expectedErr error -// } - -// func (a *reorgAction) method() string { -// return "reorg" -// } - -// func (a *reorgAction) desc() string { -// return a.description -// } - -// func (a *reorgAction) execute(t *testing.T) { -// actualErr := a.p.reorg(a.firstReorgedBlock) -// require.Equal(t, a.expectedErr, actualErr) -// } - -// // storeL1InfoTreeUpdates - -// type storeL1InfoTreeUpdatesAction struct { -// p *processor -// description string -// b block -// expectedErr error -// } - -// func (a *storeL1InfoTreeUpdatesAction) method() string { -// return "storeL1InfoTreeUpdates" -// } - -// func (a *storeL1InfoTreeUpdatesAction) desc() string { -// return a.description -// } - -// func (a *storeL1InfoTreeUpdatesAction) execute(t *testing.T) { -// actualErr := a.p.processBlock(a.b) -// require.Equal(t, a.expectedErr, actualErr) -// } +// TODO: add unit test diff --git a/localbridgesync/e2e_test.go b/localbridgesync/e2e_test.go new file mode 100644 index 00000000..c84d8d33 --- /dev/null +++ b/localbridgesync/e2e_test.go @@ -0,0 +1,3 @@ +package localbridgesync + +// TODO: add E2E test, prolly need a mock contract diff --git a/reorgdetector/reorgdetector.go b/reorgdetector/reorgdetector.go index 4b5a963b..c0b0caa2 100644 --- a/reorgdetector/reorgdetector.go +++ b/reorgdetector/reorgdetector.go @@ -140,6 +140,10 @@ type ReorgDetector struct { waitPeriodBlockAdder time.Duration } +type Config struct { + DBPath string `mapstructure:"DBPath"` +} + // New creates a new instance of ReorgDetector func New(ctx context.Context, client EthClient, dbPath string) (*ReorgDetector, error) { db, err := mdbx.NewMDBX(nil). From 08bb5f265fbdd35bbceeb7b634d9e641dfc81746 Mon Sep 17 00:00:00 2001 From: Arnau Date: Fri, 26 Jul 2024 13:38:49 +0200 Subject: [PATCH 08/18] WIP --- go.sum | 586 --------------------------------------------------------- 1 file changed, 586 deletions(-) diff --git a/go.sum b/go.sum index e5d5f8f9..e69de29b 100644 --- a/go.sum +++ b/go.sum @@ -1,586 +0,0 @@ -github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240726101945-d05a885ae884 h1:oXUct6UWuGs15WyCEKipY0Kc0BsCnMzniAz0EIFoPxs= -github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240726101945-d05a885ae884/go.mod h1:mFlcEjsm2YBBsu8atHJ3zyVnwM+Z/fMXpVmIJge+WVU= -github.com/0xPolygon/cdk-data-availability v0.0.8-0.20240712072318-72ae67613cbf h1:VWxVYeDhDURGp8pHR4kq3jwoXRazVHsQLMMIqYsO+Fw= -github.com/0xPolygon/cdk-data-availability v0.0.8-0.20240712072318-72ae67613cbf/go.mod h1:3XkZ0zn0GsvAT01MPQMmukF534CVSFmtrcoK3F/BK6Q= -github.com/0xPolygon/cdk-rpc v0.0.0-20240419104226-c0a62ba0f49d h1:sxh6hZ2jF/sxxj2jd5o1vuNNCZjYmn4aRG9SRlVaEFs= -github.com/0xPolygon/cdk-rpc v0.0.0-20240419104226-c0a62ba0f49d/go.mod h1:2scWqMMufrQXu7TikDgQ3BsyaKoX8qP26D6E262vSOg= -github.com/0xPolygonHermez/zkevm-data-streamer v0.2.3-RC4 h1:+4K+xSzv0ImbK30B/T9FauNTrTFUmWcNKYhIgwsE4C4= -github.com/0xPolygonHermez/zkevm-data-streamer v0.2.3-RC4/go.mod h1:0QkAXcFa92mFJrCbN3UPUJGJYes851yEgYHLONnaosE= -github.com/0xPolygonHermez/zkevm-ethtx-manager v0.1.9 h1:vrAezzwTNke6NroDAltGh1k2AJ6ibmZPBsG0bCltbRc= -github.com/0xPolygonHermez/zkevm-ethtx-manager v0.1.9/go.mod h1:pRqfLQVM3nbzdhy3buqjAgcVyNDKAXOHqTSgkwiKpic= -github.com/0xPolygonHermez/zkevm-synchronizer-l1 v0.6.3-0.20240712085301-0310358abb59 h1:Qwh92vFEXnpmDggQaZA3648viEQfLdMnAw/WFSY+2i8= -github.com/0xPolygonHermez/zkevm-synchronizer-l1 v0.6.3-0.20240712085301-0310358abb59/go.mod h1:/LHf8jPQeBYKABM1xUmN1dKaFVIJc9jMQDSGBDJ7CS0= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8= -github.com/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= -github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= -github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7YgDP83g= -github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= -github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= -github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= -github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA= -github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8= -github.com/VictoriaMetrics/fastcache v1.12.2 h1:N0y9ASrJ0F6h0QaC3o6uJb3NIZ9VKLjCM7NQbSmF7WI= -github.com/VictoriaMetrics/fastcache v1.12.2/go.mod h1:AmC+Nzz1+3G2eCPapF6UcsnkThDcMsQicp4xDukwJYI= -github.com/VictoriaMetrics/metrics v1.23.1 h1:/j8DzeJBxSpL2qSIdqnRFLvQQhbJyJbbEi22yMm7oL0= -github.com/VictoriaMetrics/metrics v1.23.1/go.mod h1:rAr/llLpEnAdTehiNlUxKgnjcOuROSzpw0GvjpEbvFc= -github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= -github.com/allegro/bigcache v1.2.1 h1:hg1sY1raCwic3Vnsvje6TT7/pnZba83LeFck5NrFKSc= -github.com/allegro/bigcache v1.2.1/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= -github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk= -github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg= -github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= -github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/bits-and-blooms/bitset v1.10.0 h1:ePXTeiPEazB5+opbv5fr8umg2R/1NlzgDsyepwsSr88= -github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= -github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= -github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= -github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= -github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= -github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= -github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= -github.com/c2h5oh/datasize v0.0.0-20220606134207-859f65c6625b h1:6+ZFm0flnudZzdSE0JxlhR2hKnGPcNB35BjQf4RYQDY= -github.com/c2h5oh/datasize v0.0.0-20220606134207-859f65c6625b/go.mod h1:S/7n9copUssQ56c7aAgHqftWO4LTf4xY6CGWt8Bc+3M= -github.com/cespare/cp v1.1.1 h1:nCb6ZLdB7NRaqsm91JtQTAme2SKJzXVsdPIPkyJr1MU= -github.com/cespare/cp v1.1.1/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s= -github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= -github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= -github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= -github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I= -github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= -github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaYPt5hWxV3MUfO5dFPFiOXg9CyG5/kCfayTqsJ4= -github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU= -github.com/cockroachdb/errors v1.11.1 h1:xSEW75zKaKCWzR3OfxXUxgrk/NtT4G1MiOv5lWZazG8= -github.com/cockroachdb/errors v1.11.1/go.mod h1:8MUxA3Gi6b25tYlFEBGLf+D8aISL+M4MIpiWMSNRfxw= -github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= -github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= -github.com/cockroachdb/pebble v1.1.0 h1:pcFh8CdCIt2kmEpK0OIatq67Ln9uGDYY3d5XnE0LJG4= -github.com/cockroachdb/pebble v1.1.0/go.mod h1:sEHm5NOXxyiAoKWhoFxT8xMgd/f3RA6qUqQ1BXKrh2E= -github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= -github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= -github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= -github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ= -github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= -github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= -github.com/consensys/gnark-crypto v0.12.1 h1:lHH39WuuFgVHONRl3J0LRBtuYdQTumFSDtJF7HpyG8M= -github.com/consensys/gnark-crypto v0.12.1/go.mod h1:v2Gy7L/4ZRosZ7Ivs+9SfUDr0f5UlG+EM5t7MPHiLuY= -github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= -github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c h1:uQYC5Z1mdLRPrZhHjHxufI8+2UG/i25QG92j0Er9p6I= -github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= -github.com/crate-crypto/go-kzg-4844 v1.0.0 h1:TsSgHwrkTKecKJ4kadtHi4b3xHW5dCFUDFnUp1TsawI= -github.com/crate-crypto/go-kzg-4844 v1.0.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= -github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= -github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/deckarep/golang-set/v2 v2.6.0 h1:XfcQbWM1LlMB8BsJ8N9vW5ehnnPVIw0je80NsVHagjM= -github.com/deckarep/golang-set/v2 v2.6.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= -github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0= -github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 h1:HbphB4TFFXpv7MNrT52FGrrgVXF1owhMVTHFZIlnvd4= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0/go.mod h1:DZGJHZMqrU4JJqFAWUS2UO1+lbSKsdiOoYi9Zzey7Fc= -github.com/didip/tollbooth/v6 v6.1.2 h1:Kdqxmqw9YTv0uKajBUiWQg+GURL/k4vy9gmLCL01PjQ= -github.com/didip/tollbooth/v6 v6.1.2/go.mod h1:xjcse6CTHCLuOkzsWrEgdy9WPJFv+p/x6v+MyfP+O9s= -github.com/erigontech/mdbx-go v0.27.14 h1:IVVeQVCAjZRpAR8bThlP2ISxrOwdV35NZdGwAgotaRw= -github.com/erigontech/mdbx-go v0.27.14/go.mod h1:FAMxbOgqOnRDx51j8HjuJZIgznbDwjX7LItd+/UWyA4= -github.com/ethereum/c-kzg-4844 v1.0.0 h1:0X1LBXxaEtYD9xsyj9B9ctQEZIpnvVDeoBx8aHEwTNA= -github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= -github.com/ethereum/go-ethereum v1.14.5 h1:szuFzO1MhJmweXjoM5nSAeDvjNUH3vIQoMzzQnfvjpw= -github.com/ethereum/go-ethereum v1.14.5/go.mod h1:VEDGGhSxY7IEjn98hJRFXl/uFvpRgbIIf2PpXiyGGgc= -github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0 h1:KrE8I4reeVvf7C1tm8elRjj4BdscTYzz/WAbYyf/JI4= -github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0/go.mod h1:D9AJLVXSyZQXJQVk8oh1EwjISE+sJTn2duYIZC0dy3w= -github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA= -github.com/fjl/memsize v0.0.2/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= -github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= -github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= -github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= -github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= -github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 h1:f6D9Hr8xV8uYKlyuj8XIruxlh9WjVjdh1gIicAS7ays= -github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= -github.com/getsentry/sentry-go v0.18.0 h1:MtBW5H9QgdcJabtZcuJG80BMOwaBpkRDZkxRkNC1sN0= -github.com/getsentry/sentry-go v0.18.0/go.mod h1:Kgon4Mby+FJ7ZWHFUAZgVaIa8sxHtnRJRLTXZr51aKQ= -github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= -github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= -github.com/go-gorp/gorp/v3 v3.1.0 h1:ItKF/Vbuj31dmV4jxA1qblpSwkl9g1typ24xoe70IGs= -github.com/go-gorp/gorp/v3 v3.1.0/go.mod h1:dLEjIyyRNiXvNZ8PSmzpt1GsWAUK8kjVhEpjH8TixEw= -github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= -github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= -github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= -github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= -github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= -github.com/go-pkgz/expirable-cache v0.0.3 h1:rTh6qNPp78z0bQE6HDhXBHUwqnV9i09Vm6dksJLXQDc= -github.com/go-pkgz/expirable-cache v0.0.3/go.mod h1:+IauqN00R2FqNRLCLA+X5YljQJrwB179PfiAoMPlTlQ= -github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= -github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= -github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= -github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw= -github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4= -github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= -github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= -github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= -github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw= -github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= -github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= -github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= -github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk= -github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= -github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= -github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= -github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI= -github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8= -github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE= -github.com/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0= -github.com/hashicorp/hcl v1.0.1-0.20180906183839-65a6292f0157 h1:uyodBE3xDz0ynKs1tLBU26wOQoEkAqqiY18DbZ+FZrA= -github.com/hashicorp/hcl v1.0.1-0.20180906183839-65a6292f0157/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/hermeznetwork/tracerr v0.3.2 h1:QB3TlQxO/4XHyixsg+nRZPuoel/FFQlQ7oAoHDD5l1c= -github.com/hermeznetwork/tracerr v0.3.2/go.mod h1:nsWC1+tc4qUEbUGRv4DcPJJTjLsedlPajlFmpJoohK4= -github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4 h1:X4egAf/gcS1zATw6wn4Ej8vjuVGxeHdan+bRb2ebyv4= -github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4/go.mod h1:5GuXa7vkL8u9FkFuWdVvfR5ix8hRB7DbOAaYULamFpc= -github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= -github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= -github.com/holiman/uint256 v1.2.4 h1:jUc4Nk8fm9jZabQuqr2JzednajVmBpC+oiTiXZJEApU= -github.com/holiman/uint256 v1.2.4/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc= -github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= -github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/iden3/go-iden3-crypto v0.0.16 h1:zN867xiz6HgErXVIV/6WyteGcOukE9gybYTorBMEdsk= -github.com/iden3/go-iden3-crypto v0.0.16/go.mod h1:dLpM4vEPJ3nDHzhWFXDjzkn1qHoBeOT/3UEhXsEsP3E= -github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI= -github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0= -github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo= -github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= -github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8= -github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= -github.com/jackc/pgconn v0.0.0-20190420214824-7e0022ef6ba3/go.mod h1:jkELnwuX+w9qN5YIfX0fl88Ehu4XC3keFuOJJk9pcnA= -github.com/jackc/pgconn v0.0.0-20190824142844-760dd75542eb/go.mod h1:lLjNuW/+OfW9/pnVKPazfWOgNfH2aPem8YQ7ilXGvJE= -github.com/jackc/pgconn v0.0.0-20190831204454-2fabfa3c18b7/go.mod h1:ZJKsE/KZfsUgOEh9hBm+xYTstcNHg7UPMVJqRfQxq4s= -github.com/jackc/pgconn v1.8.0/go.mod h1:1C2Pb36bGIP9QHGBYCjnyhqu7Rv3sGshaQUvmfGIB/o= -github.com/jackc/pgconn v1.9.0/go.mod h1:YctiPyvzfU11JFxoXokUOOKQXQmDMoJL9vJzHH8/2JY= -github.com/jackc/pgconn v1.9.1-0.20210724152538-d89c8390a530/go.mod h1:4z2w8XhRbP1hYxkpTuBjTS3ne3J48K83+u0zoyvg2pI= -github.com/jackc/pgconn v1.14.3 h1:bVoTr12EGANZz66nZPkMInAV/KHD2TxH9npjXXgiB3w= -github.com/jackc/pgconn v1.14.3/go.mod h1:RZbme4uasqzybK2RK5c65VsHxoyaml09lx3tXOcO/VM= -github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE= -github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8= -github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE= -github.com/jackc/pgmock v0.0.0-20201204152224-4fe30f7445fd/go.mod h1:hrBW0Enj2AZTNpt/7Y5rr2xe/9Mn757Wtb2xeBzPv2c= -github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65 h1:DadwsjnMwFjfWc9y5Wi/+Zz7xoE5ALHsRQlOctkOiHc= -github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65/go.mod h1:5R2h2EEX+qri8jOWMbJCtaPWkrrNc7OHwsp2TCqp7ak= -github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= -github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= -github.com/jackc/pgproto3 v1.1.0/go.mod h1:eR5FA3leWg7p9aeAqi37XOTgTIbkABlvcPB3E5rlc78= -github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190420180111-c116219b62db/go.mod h1:bhq50y+xrl9n5mRYyCBFKkpRVTLYJVWeCc+mEAI3yXA= -github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190609003834-432c2951c711/go.mod h1:uH0AWtUmuShn0bcesswc4aBTWGvw0cAxIJp+6OB//Wg= -github.com/jackc/pgproto3/v2 v2.0.0-rc3/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM= -github.com/jackc/pgproto3/v2 v2.0.0-rc3.0.20190831210041-4c03ce451f29/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM= -github.com/jackc/pgproto3/v2 v2.0.6/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= -github.com/jackc/pgproto3/v2 v2.1.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= -github.com/jackc/pgproto3/v2 v2.3.3 h1:1HLSx5H+tXR9pW3in3zaztoEwQYRC9SQaYUHjTSUOag= -github.com/jackc/pgproto3/v2 v2.3.3/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= -github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E= -github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= -github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= -github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01CGwFsrv11mJRHWJ6aifDLfdV3aVjFF0zg= -github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc= -github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59/go.mod h1:MWlu30kVJrUS8lot6TQqcg7mtthZ9T0EoIBFiJcmcyw= -github.com/jackc/pgtype v1.8.1-0.20210724151600-32e20a603178/go.mod h1:C516IlIV9NKqfsMCXTdChteoXmwgUceqaLfjg2e3NlM= -github.com/jackc/pgtype v1.14.0 h1:y+xUdabmyMkJLyApYuPj38mW+aAIqCe5uuBB51rH3Vw= -github.com/jackc/pgtype v1.14.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4= -github.com/jackc/pgx/v4 v4.0.0-20190420224344-cc3461e65d96/go.mod h1:mdxmSJJuR08CZQyj1PVQBHy9XOp5p8/SHH6a0psbY9Y= -github.com/jackc/pgx/v4 v4.0.0-20190421002000-1b8f0016e912/go.mod h1:no/Y67Jkk/9WuGR0JG/JseM9irFbnEPbuWV2EELPNuM= -github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQnOEnf1dqHGpw7JmHqHc1NxDoalibchSk9/RWuDc= -github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgSXP7iUjYm9C1NxKhny7lq6ee99u/z+IHFcgs= -github.com/jackc/pgx/v4 v4.18.3 h1:dE2/TrEsGX3RBprb3qryqSV9Y60iZN1C6i8IrmW9/BA= -github.com/jackc/pgx/v4 v4.18.3/go.mod h1:Ey4Oru5tH5sB6tV7hDmfWFahwF15Eb7DNXlRKx2CkVw= -github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= -github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= -github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= -github.com/jackc/puddle v1.3.0 h1:eHK/5clGOatcjX3oWGBO/MpxpbHzSwud5EWTSCI+MX0= -github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= -github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= -github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= -github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA= -github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks= -github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= -github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4= -github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= -github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= -github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= -github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= -github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= -github.com/ledgerwatch/erigon-lib v1.0.0 h1:2o7EfgB/6CyjXAaQ8+Dh7AmY5rWvwSKg0kGp/U9kwqE= -github.com/ledgerwatch/erigon-lib v1.0.0/go.mod h1:l1i6+H9MgizD+ObQ5cXsfA9S3egYTOCnnYGjbrJMqR4= -github.com/ledgerwatch/log/v3 v3.9.0 h1:iDwrXe0PVwBC68Dd94YSsHbMgQ3ufsgjzXtFNFVZFRk= -github.com/ledgerwatch/log/v3 v3.9.0/go.mod h1:EiAY6upmI/6LkNhOVxb4eVsmsP11HZCnZ3PlJMjYiqE= -github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= -github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= -github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= -github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= -github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= -github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= -github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= -github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8= -github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= -github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= -github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= -github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= -github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= -github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= -github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= -github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= -github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= -github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= -github.com/mattn/go-sqlite3 v1.14.19 h1:fhGleo2h1p8tVChob4I9HpmVFIAkKGpiukdrgQbWfGI= -github.com/mattn/go-sqlite3 v1.14.19/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= -github.com/miguelmota/go-solidity-sha3 v0.1.1 h1:3Y08sKZDtudtE5kbTBPC9RYJznoSYyWI9VD6mghU0CA= -github.com/miguelmota/go-solidity-sha3 v0.1.1/go.mod h1:sax1FvQF+f71j8W1uUHMZn8NxKyl5rYLks2nqj8RFEw= -github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= -github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A= -github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4= -github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= -github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= -github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= -github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= -github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= -github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= -github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= -github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= -github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= -github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= -github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= -github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= -github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= -github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= -github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0= -github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y= -github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= -github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= -github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= -github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= -github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/poy/onpar v1.1.2 h1:QaNrNiZx0+Nar5dLgTVp5mXkyoVFIbepjyEoGSnhbAY= -github.com/poy/onpar v1.1.2/go.mod h1:6X8FLNoxyr9kkmnlqpK6LSoiOtrO6MICtWwEuWkLjzg= -github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE= -github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho= -github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= -github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= -github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE= -github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc= -github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= -github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= -github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= -github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= -github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= -github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= -github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= -github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= -github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= -github.com/rubenv/sql-migrate v1.6.1 h1:bo6/sjsan9HaXAsNxYP/jCEDUGibHp8JmOBw7NTGRos= -github.com/rubenv/sql-migrate v1.6.1/go.mod h1:tPzespupJS0jacLfhbwto/UjSX+8h2FdWB7ar+QlHa0= -github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= -github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= -github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= -github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= -github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= -github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= -github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= -github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= -github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= -github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= -github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= -github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= -github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= -github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= -github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= -github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= -github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= -github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= -github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI= -github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg= -github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA= -github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= -github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= -github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4= -github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= -github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a h1:1ur3QoCqvE5fl+nylMaIr9PVV1w343YRDtsy+Rwu7XI= -github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48= -github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= -github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= -github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= -github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= -github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8= -github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U= -github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI= -github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM= -github.com/valyala/fastrand v1.1.0 h1:f+5HkLW4rsgzdNoleUOB69hyT9IlD2ZQh9GyDMfb5G8= -github.com/valyala/fastrand v1.1.0/go.mod h1:HWqCzkrkg6QXT8V2EXWvXCoow7vLwOFN002oeRzjapQ= -github.com/valyala/histogram v1.2.0 h1:wyYGAZZt3CpwUiIb9AU/Zbllg1llXyrtApRS815OLoQ= -github.com/valyala/histogram v1.2.0/go.mod h1:Hb4kBwb4UxsaNbbbh+RRz8ZR6pdodR57tzWUS3BUzXY= -github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc= -github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw= -github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw= -github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk= -github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= -go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= -go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= -go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= -go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= -go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= -go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= -go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= -go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= -go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= -go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= -go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= -golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= -golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= -golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= -golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ= -golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= -golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= -golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= -golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= -golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:NnYq6UN9ReLM9/Y01KWNOWyI5xQ9kbIms5GGJVwS/Yc= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= -google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= -google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= -google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s= -gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= -gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= -gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU= -rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA= From 11ec3af1ecb98b04928e4645a2d38fabb5b77a19 Mon Sep 17 00:00:00 2001 From: bros Date: Fri, 26 Jul 2024 12:40:30 +0000 Subject: [PATCH 09/18] wip --- Makefile | 2 +- go.sum | 586 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 587 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d092a0f3..e081dcb7 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ else endif GOBASE := $(shell pwd) GOBIN := $(GOBASE)/dist -GOENVVARS := GOBIN=$(GOBIN) CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) +GOENVVARS := GOBIN=$(GOBIN) CGO_ENABLED=1 GOOS=linux GOARCH=$(ARCH) GOBINARY := cdk GOCMD := $(GOBASE)/cmd diff --git a/go.sum b/go.sum index e69de29b..e5d5f8f9 100644 --- a/go.sum +++ b/go.sum @@ -0,0 +1,586 @@ +github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240726101945-d05a885ae884 h1:oXUct6UWuGs15WyCEKipY0Kc0BsCnMzniAz0EIFoPxs= +github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240726101945-d05a885ae884/go.mod h1:mFlcEjsm2YBBsu8atHJ3zyVnwM+Z/fMXpVmIJge+WVU= +github.com/0xPolygon/cdk-data-availability v0.0.8-0.20240712072318-72ae67613cbf h1:VWxVYeDhDURGp8pHR4kq3jwoXRazVHsQLMMIqYsO+Fw= +github.com/0xPolygon/cdk-data-availability v0.0.8-0.20240712072318-72ae67613cbf/go.mod h1:3XkZ0zn0GsvAT01MPQMmukF534CVSFmtrcoK3F/BK6Q= +github.com/0xPolygon/cdk-rpc v0.0.0-20240419104226-c0a62ba0f49d h1:sxh6hZ2jF/sxxj2jd5o1vuNNCZjYmn4aRG9SRlVaEFs= +github.com/0xPolygon/cdk-rpc v0.0.0-20240419104226-c0a62ba0f49d/go.mod h1:2scWqMMufrQXu7TikDgQ3BsyaKoX8qP26D6E262vSOg= +github.com/0xPolygonHermez/zkevm-data-streamer v0.2.3-RC4 h1:+4K+xSzv0ImbK30B/T9FauNTrTFUmWcNKYhIgwsE4C4= +github.com/0xPolygonHermez/zkevm-data-streamer v0.2.3-RC4/go.mod h1:0QkAXcFa92mFJrCbN3UPUJGJYes851yEgYHLONnaosE= +github.com/0xPolygonHermez/zkevm-ethtx-manager v0.1.9 h1:vrAezzwTNke6NroDAltGh1k2AJ6ibmZPBsG0bCltbRc= +github.com/0xPolygonHermez/zkevm-ethtx-manager v0.1.9/go.mod h1:pRqfLQVM3nbzdhy3buqjAgcVyNDKAXOHqTSgkwiKpic= +github.com/0xPolygonHermez/zkevm-synchronizer-l1 v0.6.3-0.20240712085301-0310358abb59 h1:Qwh92vFEXnpmDggQaZA3648viEQfLdMnAw/WFSY+2i8= +github.com/0xPolygonHermez/zkevm-synchronizer-l1 v0.6.3-0.20240712085301-0310358abb59/go.mod h1:/LHf8jPQeBYKABM1xUmN1dKaFVIJc9jMQDSGBDJ7CS0= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8= +github.com/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= +github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= +github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7YgDP83g= +github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= +github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= +github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= +github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA= +github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8= +github.com/VictoriaMetrics/fastcache v1.12.2 h1:N0y9ASrJ0F6h0QaC3o6uJb3NIZ9VKLjCM7NQbSmF7WI= +github.com/VictoriaMetrics/fastcache v1.12.2/go.mod h1:AmC+Nzz1+3G2eCPapF6UcsnkThDcMsQicp4xDukwJYI= +github.com/VictoriaMetrics/metrics v1.23.1 h1:/j8DzeJBxSpL2qSIdqnRFLvQQhbJyJbbEi22yMm7oL0= +github.com/VictoriaMetrics/metrics v1.23.1/go.mod h1:rAr/llLpEnAdTehiNlUxKgnjcOuROSzpw0GvjpEbvFc= +github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= +github.com/allegro/bigcache v1.2.1 h1:hg1sY1raCwic3Vnsvje6TT7/pnZba83LeFck5NrFKSc= +github.com/allegro/bigcache v1.2.1/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= +github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk= +github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bits-and-blooms/bitset v1.10.0 h1:ePXTeiPEazB5+opbv5fr8umg2R/1NlzgDsyepwsSr88= +github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= +github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= +github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= +github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= +github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= +github.com/c2h5oh/datasize v0.0.0-20220606134207-859f65c6625b h1:6+ZFm0flnudZzdSE0JxlhR2hKnGPcNB35BjQf4RYQDY= +github.com/c2h5oh/datasize v0.0.0-20220606134207-859f65c6625b/go.mod h1:S/7n9copUssQ56c7aAgHqftWO4LTf4xY6CGWt8Bc+3M= +github.com/cespare/cp v1.1.1 h1:nCb6ZLdB7NRaqsm91JtQTAme2SKJzXVsdPIPkyJr1MU= +github.com/cespare/cp v1.1.1/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I= +github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= +github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaYPt5hWxV3MUfO5dFPFiOXg9CyG5/kCfayTqsJ4= +github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU= +github.com/cockroachdb/errors v1.11.1 h1:xSEW75zKaKCWzR3OfxXUxgrk/NtT4G1MiOv5lWZazG8= +github.com/cockroachdb/errors v1.11.1/go.mod h1:8MUxA3Gi6b25tYlFEBGLf+D8aISL+M4MIpiWMSNRfxw= +github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= +github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= +github.com/cockroachdb/pebble v1.1.0 h1:pcFh8CdCIt2kmEpK0OIatq67Ln9uGDYY3d5XnE0LJG4= +github.com/cockroachdb/pebble v1.1.0/go.mod h1:sEHm5NOXxyiAoKWhoFxT8xMgd/f3RA6qUqQ1BXKrh2E= +github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= +github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= +github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= +github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ= +github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= +github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= +github.com/consensys/gnark-crypto v0.12.1 h1:lHH39WuuFgVHONRl3J0LRBtuYdQTumFSDtJF7HpyG8M= +github.com/consensys/gnark-crypto v0.12.1/go.mod h1:v2Gy7L/4ZRosZ7Ivs+9SfUDr0f5UlG+EM5t7MPHiLuY= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c h1:uQYC5Z1mdLRPrZhHjHxufI8+2UG/i25QG92j0Er9p6I= +github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= +github.com/crate-crypto/go-kzg-4844 v1.0.0 h1:TsSgHwrkTKecKJ4kadtHi4b3xHW5dCFUDFnUp1TsawI= +github.com/crate-crypto/go-kzg-4844 v1.0.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= +github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/deckarep/golang-set/v2 v2.6.0 h1:XfcQbWM1LlMB8BsJ8N9vW5ehnnPVIw0je80NsVHagjM= +github.com/deckarep/golang-set/v2 v2.6.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= +github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0= +github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 h1:HbphB4TFFXpv7MNrT52FGrrgVXF1owhMVTHFZIlnvd4= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0/go.mod h1:DZGJHZMqrU4JJqFAWUS2UO1+lbSKsdiOoYi9Zzey7Fc= +github.com/didip/tollbooth/v6 v6.1.2 h1:Kdqxmqw9YTv0uKajBUiWQg+GURL/k4vy9gmLCL01PjQ= +github.com/didip/tollbooth/v6 v6.1.2/go.mod h1:xjcse6CTHCLuOkzsWrEgdy9WPJFv+p/x6v+MyfP+O9s= +github.com/erigontech/mdbx-go v0.27.14 h1:IVVeQVCAjZRpAR8bThlP2ISxrOwdV35NZdGwAgotaRw= +github.com/erigontech/mdbx-go v0.27.14/go.mod h1:FAMxbOgqOnRDx51j8HjuJZIgznbDwjX7LItd+/UWyA4= +github.com/ethereum/c-kzg-4844 v1.0.0 h1:0X1LBXxaEtYD9xsyj9B9ctQEZIpnvVDeoBx8aHEwTNA= +github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= +github.com/ethereum/go-ethereum v1.14.5 h1:szuFzO1MhJmweXjoM5nSAeDvjNUH3vIQoMzzQnfvjpw= +github.com/ethereum/go-ethereum v1.14.5/go.mod h1:VEDGGhSxY7IEjn98hJRFXl/uFvpRgbIIf2PpXiyGGgc= +github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0 h1:KrE8I4reeVvf7C1tm8elRjj4BdscTYzz/WAbYyf/JI4= +github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0/go.mod h1:D9AJLVXSyZQXJQVk8oh1EwjISE+sJTn2duYIZC0dy3w= +github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA= +github.com/fjl/memsize v0.0.2/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 h1:f6D9Hr8xV8uYKlyuj8XIruxlh9WjVjdh1gIicAS7ays= +github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= +github.com/getsentry/sentry-go v0.18.0 h1:MtBW5H9QgdcJabtZcuJG80BMOwaBpkRDZkxRkNC1sN0= +github.com/getsentry/sentry-go v0.18.0/go.mod h1:Kgon4Mby+FJ7ZWHFUAZgVaIa8sxHtnRJRLTXZr51aKQ= +github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= +github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= +github.com/go-gorp/gorp/v3 v3.1.0 h1:ItKF/Vbuj31dmV4jxA1qblpSwkl9g1typ24xoe70IGs= +github.com/go-gorp/gorp/v3 v3.1.0/go.mod h1:dLEjIyyRNiXvNZ8PSmzpt1GsWAUK8kjVhEpjH8TixEw= +github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= +github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= +github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= +github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= +github.com/go-pkgz/expirable-cache v0.0.3 h1:rTh6qNPp78z0bQE6HDhXBHUwqnV9i09Vm6dksJLXQDc= +github.com/go-pkgz/expirable-cache v0.0.3/go.mod h1:+IauqN00R2FqNRLCLA+X5YljQJrwB179PfiAoMPlTlQ= +github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= +github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= +github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw= +github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= +github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= +github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= +github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw= +github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= +github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk= +github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= +github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= +github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= +github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI= +github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8= +github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE= +github.com/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0= +github.com/hashicorp/hcl v1.0.1-0.20180906183839-65a6292f0157 h1:uyodBE3xDz0ynKs1tLBU26wOQoEkAqqiY18DbZ+FZrA= +github.com/hashicorp/hcl v1.0.1-0.20180906183839-65a6292f0157/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hermeznetwork/tracerr v0.3.2 h1:QB3TlQxO/4XHyixsg+nRZPuoel/FFQlQ7oAoHDD5l1c= +github.com/hermeznetwork/tracerr v0.3.2/go.mod h1:nsWC1+tc4qUEbUGRv4DcPJJTjLsedlPajlFmpJoohK4= +github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4 h1:X4egAf/gcS1zATw6wn4Ej8vjuVGxeHdan+bRb2ebyv4= +github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4/go.mod h1:5GuXa7vkL8u9FkFuWdVvfR5ix8hRB7DbOAaYULamFpc= +github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= +github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= +github.com/holiman/uint256 v1.2.4 h1:jUc4Nk8fm9jZabQuqr2JzednajVmBpC+oiTiXZJEApU= +github.com/holiman/uint256 v1.2.4/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc= +github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= +github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/iden3/go-iden3-crypto v0.0.16 h1:zN867xiz6HgErXVIV/6WyteGcOukE9gybYTorBMEdsk= +github.com/iden3/go-iden3-crypto v0.0.16/go.mod h1:dLpM4vEPJ3nDHzhWFXDjzkn1qHoBeOT/3UEhXsEsP3E= +github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI= +github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0= +github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo= +github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= +github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8= +github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= +github.com/jackc/pgconn v0.0.0-20190420214824-7e0022ef6ba3/go.mod h1:jkELnwuX+w9qN5YIfX0fl88Ehu4XC3keFuOJJk9pcnA= +github.com/jackc/pgconn v0.0.0-20190824142844-760dd75542eb/go.mod h1:lLjNuW/+OfW9/pnVKPazfWOgNfH2aPem8YQ7ilXGvJE= +github.com/jackc/pgconn v0.0.0-20190831204454-2fabfa3c18b7/go.mod h1:ZJKsE/KZfsUgOEh9hBm+xYTstcNHg7UPMVJqRfQxq4s= +github.com/jackc/pgconn v1.8.0/go.mod h1:1C2Pb36bGIP9QHGBYCjnyhqu7Rv3sGshaQUvmfGIB/o= +github.com/jackc/pgconn v1.9.0/go.mod h1:YctiPyvzfU11JFxoXokUOOKQXQmDMoJL9vJzHH8/2JY= +github.com/jackc/pgconn v1.9.1-0.20210724152538-d89c8390a530/go.mod h1:4z2w8XhRbP1hYxkpTuBjTS3ne3J48K83+u0zoyvg2pI= +github.com/jackc/pgconn v1.14.3 h1:bVoTr12EGANZz66nZPkMInAV/KHD2TxH9npjXXgiB3w= +github.com/jackc/pgconn v1.14.3/go.mod h1:RZbme4uasqzybK2RK5c65VsHxoyaml09lx3tXOcO/VM= +github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE= +github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8= +github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE= +github.com/jackc/pgmock v0.0.0-20201204152224-4fe30f7445fd/go.mod h1:hrBW0Enj2AZTNpt/7Y5rr2xe/9Mn757Wtb2xeBzPv2c= +github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65 h1:DadwsjnMwFjfWc9y5Wi/+Zz7xoE5ALHsRQlOctkOiHc= +github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65/go.mod h1:5R2h2EEX+qri8jOWMbJCtaPWkrrNc7OHwsp2TCqp7ak= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= +github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgproto3 v1.1.0/go.mod h1:eR5FA3leWg7p9aeAqi37XOTgTIbkABlvcPB3E5rlc78= +github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190420180111-c116219b62db/go.mod h1:bhq50y+xrl9n5mRYyCBFKkpRVTLYJVWeCc+mEAI3yXA= +github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190609003834-432c2951c711/go.mod h1:uH0AWtUmuShn0bcesswc4aBTWGvw0cAxIJp+6OB//Wg= +github.com/jackc/pgproto3/v2 v2.0.0-rc3/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM= +github.com/jackc/pgproto3/v2 v2.0.0-rc3.0.20190831210041-4c03ce451f29/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM= +github.com/jackc/pgproto3/v2 v2.0.6/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= +github.com/jackc/pgproto3/v2 v2.1.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= +github.com/jackc/pgproto3/v2 v2.3.3 h1:1HLSx5H+tXR9pW3in3zaztoEwQYRC9SQaYUHjTSUOag= +github.com/jackc/pgproto3/v2 v2.3.3/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= +github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01CGwFsrv11mJRHWJ6aifDLfdV3aVjFF0zg= +github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc= +github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59/go.mod h1:MWlu30kVJrUS8lot6TQqcg7mtthZ9T0EoIBFiJcmcyw= +github.com/jackc/pgtype v1.8.1-0.20210724151600-32e20a603178/go.mod h1:C516IlIV9NKqfsMCXTdChteoXmwgUceqaLfjg2e3NlM= +github.com/jackc/pgtype v1.14.0 h1:y+xUdabmyMkJLyApYuPj38mW+aAIqCe5uuBB51rH3Vw= +github.com/jackc/pgtype v1.14.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4= +github.com/jackc/pgx/v4 v4.0.0-20190420224344-cc3461e65d96/go.mod h1:mdxmSJJuR08CZQyj1PVQBHy9XOp5p8/SHH6a0psbY9Y= +github.com/jackc/pgx/v4 v4.0.0-20190421002000-1b8f0016e912/go.mod h1:no/Y67Jkk/9WuGR0JG/JseM9irFbnEPbuWV2EELPNuM= +github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQnOEnf1dqHGpw7JmHqHc1NxDoalibchSk9/RWuDc= +github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgSXP7iUjYm9C1NxKhny7lq6ee99u/z+IHFcgs= +github.com/jackc/pgx/v4 v4.18.3 h1:dE2/TrEsGX3RBprb3qryqSV9Y60iZN1C6i8IrmW9/BA= +github.com/jackc/pgx/v4 v4.18.3/go.mod h1:Ey4Oru5tH5sB6tV7hDmfWFahwF15Eb7DNXlRKx2CkVw= +github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= +github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= +github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= +github.com/jackc/puddle v1.3.0 h1:eHK/5clGOatcjX3oWGBO/MpxpbHzSwud5EWTSCI+MX0= +github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= +github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= +github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= +github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA= +github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4= +github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= +github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= +github.com/ledgerwatch/erigon-lib v1.0.0 h1:2o7EfgB/6CyjXAaQ8+Dh7AmY5rWvwSKg0kGp/U9kwqE= +github.com/ledgerwatch/erigon-lib v1.0.0/go.mod h1:l1i6+H9MgizD+ObQ5cXsfA9S3egYTOCnnYGjbrJMqR4= +github.com/ledgerwatch/log/v3 v3.9.0 h1:iDwrXe0PVwBC68Dd94YSsHbMgQ3ufsgjzXtFNFVZFRk= +github.com/ledgerwatch/log/v3 v3.9.0/go.mod h1:EiAY6upmI/6LkNhOVxb4eVsmsP11HZCnZ3PlJMjYiqE= +github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= +github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= +github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8= +github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= +github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= +github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= +github.com/mattn/go-sqlite3 v1.14.19 h1:fhGleo2h1p8tVChob4I9HpmVFIAkKGpiukdrgQbWfGI= +github.com/mattn/go-sqlite3 v1.14.19/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= +github.com/miguelmota/go-solidity-sha3 v0.1.1 h1:3Y08sKZDtudtE5kbTBPC9RYJznoSYyWI9VD6mghU0CA= +github.com/miguelmota/go-solidity-sha3 v0.1.1/go.mod h1:sax1FvQF+f71j8W1uUHMZn8NxKyl5rYLks2nqj8RFEw= +github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A= +github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4= +github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= +github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= +github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= +github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= +github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= +github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= +github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= +github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= +github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= +github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0= +github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= +github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/poy/onpar v1.1.2 h1:QaNrNiZx0+Nar5dLgTVp5mXkyoVFIbepjyEoGSnhbAY= +github.com/poy/onpar v1.1.2/go.mod h1:6X8FLNoxyr9kkmnlqpK6LSoiOtrO6MICtWwEuWkLjzg= +github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE= +github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho= +github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= +github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= +github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE= +github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc= +github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= +github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= +github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= +github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= +github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= +github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= +github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= +github.com/rubenv/sql-migrate v1.6.1 h1:bo6/sjsan9HaXAsNxYP/jCEDUGibHp8JmOBw7NTGRos= +github.com/rubenv/sql-migrate v1.6.1/go.mod h1:tPzespupJS0jacLfhbwto/UjSX+8h2FdWB7ar+QlHa0= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= +github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= +github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= +github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= +github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= +github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= +github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= +github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= +github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= +github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= +github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= +github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= +github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= +github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= +github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= +github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= +github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI= +github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg= +github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA= +github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= +github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4= +github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= +github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a h1:1ur3QoCqvE5fl+nylMaIr9PVV1w343YRDtsy+Rwu7XI= +github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48= +github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= +github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= +github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8= +github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U= +github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI= +github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM= +github.com/valyala/fastrand v1.1.0 h1:f+5HkLW4rsgzdNoleUOB69hyT9IlD2ZQh9GyDMfb5G8= +github.com/valyala/fastrand v1.1.0/go.mod h1:HWqCzkrkg6QXT8V2EXWvXCoow7vLwOFN002oeRzjapQ= +github.com/valyala/histogram v1.2.0 h1:wyYGAZZt3CpwUiIb9AU/Zbllg1llXyrtApRS815OLoQ= +github.com/valyala/histogram v1.2.0/go.mod h1:Hb4kBwb4UxsaNbbbh+RRz8ZR6pdodR57tzWUS3BUzXY= +github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc= +github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw= +github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw= +github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= +go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= +go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= +go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= +go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= +go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= +golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= +golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= +golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ= +golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= +golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= +golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= +golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:NnYq6UN9ReLM9/Y01KWNOWyI5xQ9kbIms5GGJVwS/Yc= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= +google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= +google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= +gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU= +rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA= From f6bf0ad71d5184b06322e4127db7dd2dd71c8b0b Mon Sep 17 00:00:00 2001 From: bros Date: Fri, 26 Jul 2024 12:55:06 +0000 Subject: [PATCH 10/18] WIP --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index ded6db29..d40eaa56 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.4 require ( github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240726101945-d05a885ae884 - github.com/0xPolygon/cdk-data-availability v0.0.8-0.20240712072318-72ae67613cbf + github.com/0xPolygon/cdk-data-availability v0.0.8 github.com/0xPolygon/cdk-rpc v0.0.0-20240419104226-c0a62ba0f49d github.com/0xPolygonHermez/zkevm-data-streamer v0.2.3-RC4 github.com/0xPolygonHermez/zkevm-ethtx-manager v0.1.9 diff --git a/go.sum b/go.sum index e5d5f8f9..41d4b0f0 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240726101945-d05a885ae884 h1 github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240726101945-d05a885ae884/go.mod h1:mFlcEjsm2YBBsu8atHJ3zyVnwM+Z/fMXpVmIJge+WVU= github.com/0xPolygon/cdk-data-availability v0.0.8-0.20240712072318-72ae67613cbf h1:VWxVYeDhDURGp8pHR4kq3jwoXRazVHsQLMMIqYsO+Fw= github.com/0xPolygon/cdk-data-availability v0.0.8-0.20240712072318-72ae67613cbf/go.mod h1:3XkZ0zn0GsvAT01MPQMmukF534CVSFmtrcoK3F/BK6Q= +github.com/0xPolygon/cdk-data-availability v0.0.8 h1:bMmOYZ7Ei683y80ric3KzMPXtRGmchAmfjIRzghaHb4= +github.com/0xPolygon/cdk-data-availability v0.0.8/go.mod h1:3XkZ0zn0GsvAT01MPQMmukF534CVSFmtrcoK3F/BK6Q= github.com/0xPolygon/cdk-rpc v0.0.0-20240419104226-c0a62ba0f49d h1:sxh6hZ2jF/sxxj2jd5o1vuNNCZjYmn4aRG9SRlVaEFs= github.com/0xPolygon/cdk-rpc v0.0.0-20240419104226-c0a62ba0f49d/go.mod h1:2scWqMMufrQXu7TikDgQ3BsyaKoX8qP26D6E262vSOg= github.com/0xPolygonHermez/zkevm-data-streamer v0.2.3-RC4 h1:+4K+xSzv0ImbK30B/T9FauNTrTFUmWcNKYhIgwsE4C4= From 26ce165f72f598317a1842595a4adfacc2e7d2b1 Mon Sep 17 00:00:00 2001 From: bros Date: Fri, 26 Jul 2024 13:18:50 +0000 Subject: [PATCH 11/18] start reorg detector --- Makefile | 2 +- cmd/run.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e081dcb7..d092a0f3 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ else endif GOBASE := $(shell pwd) GOBIN := $(GOBASE)/dist -GOENVVARS := GOBIN=$(GOBIN) CGO_ENABLED=1 GOOS=linux GOARCH=$(ARCH) +GOENVVARS := GOBIN=$(GOBIN) CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) GOBINARY := cdk GOCMD := $(GOBASE)/cmd diff --git a/cmd/run.go b/cmd/run.go index 57fc2e4d..ab97f089 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -76,6 +76,7 @@ func start(cliCtx *cli.Context) error { log.Fatal(err) } reorgDetector := newReorgDetectorL1(cliCtx.Context, *c, l1Client) + go reorgDetector.Start(cliCtx.Context) syncer := newL1InfoTreeSyncer(cliCtx.Context, *c, l1Client, reorgDetector) go syncer.Start(cliCtx.Context) aggOracle := createAggoracle(*c, l1Client, syncer) From 4354830742ebb5afb3687e892b5ca386d0879e37 Mon Sep 17 00:00:00 2001 From: bros Date: Fri, 26 Jul 2024 13:36:56 +0000 Subject: [PATCH 12/18] fix docker --- Dockerfile | 7 ++++--- Makefile | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0b509075..18224428 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,9 @@ # CONTAINER FOR BUILDING BINARY -FROM golang:1.22.4 AS build +FROM golang:1.22.5-alpine3.20 AS build WORKDIR $GOPATH/src/github.com/0xPolygon/cdk +RUN apk update && apk add --no-cache make build-base git # INSTALL DEPENDENCIES COPY go.mod go.sum /src/ RUN cd /src && go mod download @@ -12,9 +13,9 @@ COPY . /src RUN cd /src && make build # CONTAINER FOR RUNNING BINARY -FROM alpine:3.18.4 +FROM alpine:3.20 COPY --from=build /src/dist/cdk /app/cdk RUN mkdir /app/data && apk update && apk add postgresql15-client EXPOSE 8123 -CMD ["/bin/sh", "-c", "/app/cdk run"] +CMD ["/bin/sh", "-c", "/app/cdk run"] \ No newline at end of file diff --git a/Makefile b/Makefile index d092a0f3..e081dcb7 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ else endif GOBASE := $(shell pwd) GOBIN := $(GOBASE)/dist -GOENVVARS := GOBIN=$(GOBIN) CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) +GOENVVARS := GOBIN=$(GOBIN) CGO_ENABLED=1 GOOS=linux GOARCH=$(ARCH) GOBINARY := cdk GOCMD := $(GOBASE)/cmd From f66c3373f5b5b78e68b325ee5ee554ae722d9527 Mon Sep 17 00:00:00 2001 From: bros Date: Fri, 26 Jul 2024 15:36:05 +0000 Subject: [PATCH 13/18] pass test with docker --- aggoracle/config.go | 7 +++--- aggoracle/oracle.go | 6 +++++- cmd/run.go | 4 ++++ l1infotreesync/processor.go | 43 +++++++++++++++++-------------------- 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/aggoracle/config.go b/aggoracle/config.go index d78747da..2dd39403 100644 --- a/aggoracle/config.go +++ b/aggoracle/config.go @@ -16,9 +16,10 @@ var ( ) type Config struct { - TargetChainType TargetChainType `mapstructure:"TargetChainType"` - EVMSender chaingersender.EVMConfig `mapstructure:"EVMSender"` - URLRPCL1 string `mapstructure:"URLRPCL1"` + TargetChainType TargetChainType `mapstructure:"TargetChainType"` + URLRPCL1 string `mapstructure:"URLRPCL1"` + // TODO: BlockFinality doesnt work as per the jsonschema BlockFinality string `jsonschema:"enum=latest,enum=safe, enum=pending, enum=finalized" mapstructure:"BlockFinality"` WaitPeriodNextGER types.Duration `mapstructure:"WaitPeriodNextGER"` + EVMSender chaingersender.EVMConfig `mapstructure:"EVMSender"` } diff --git a/aggoracle/oracle.go b/aggoracle/oracle.go index 8f4b7a67..291950c5 100644 --- a/aggoracle/oracle.go +++ b/aggoracle/oracle.go @@ -64,7 +64,11 @@ func (a *AggOracle) Start(ctx context.Context) { case <-a.ticker.C: gerToInject, err := a.getLastFinalisedGER(ctx) if err != nil { - log.Error("error calling getLastFinalisedGER: ", err) + if err == l1infotreesync.ErrBlockNotProcessed || err == l1infotreesync.ErrNotFound { + log.Debugf("syncer is not ready: %v", err) + } else { + log.Error("error calling isGERAlreadyInjected: ", err) + } continue } if alreadyInjectd, err := a.chainSender.IsGERAlreadyInjected(gerToInject); err != nil { diff --git a/cmd/run.go b/cmd/run.go index ab97f089..4bb24fc4 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -208,6 +208,10 @@ func createAggoracle(cfg config.Config, l1Client *ethclient.Client, syncer *l1in Outputs: cfg.Log.Outputs, } ethTxManager, err := ethtxmanager.New(cfg.AggOracle.EVMSender.EthTxManager) + if err != nil { + log.Fatal(err) + } + go ethTxManager.Start() l2CLient, err := ethclient.Dial(cfg.AggOracle.EVMSender.URLRPCL2) if err != nil { log.Fatal(err) diff --git a/l1infotreesync/processor.go b/l1infotreesync/processor.go index fcb8b028..2e6116c4 100644 --- a/l1infotreesync/processor.go +++ b/l1infotreesync/processor.go @@ -8,6 +8,7 @@ import ( "github.com/0xPolygon/cdk/common" "github.com/0xPolygon/cdk/l1infotree" + "github.com/0xPolygon/cdk/log" "github.com/0xPolygon/cdk/sync" ethCommon "github.com/ethereum/go-ethereum/common" "github.com/ledgerwatch/erigon-lib/kv" @@ -186,7 +187,8 @@ func (p *processor) GetInfoByRoot(ctx context.Context, root ethCommon.Hash) (*L1 return p.getInfoByHashWithTx(tx, hash) } -// GetLatestInfoUntilBlock returns the most recent L1InfoTreeLeaf that occured before or at blockNum +// GetLatestInfoUntilBlock returns the most recent L1InfoTreeLeaf that occured before or at blockNum. +// If the blockNum has not been processed yet the error ErrBlockNotProcessed will be returned func (p *processor) GetLatestInfoUntilBlock(ctx context.Context, blockNum uint64) (*L1InfoTreeLeaf, error) { tx, err := p.db.BeginRo(ctx) if err != nil { @@ -197,32 +199,26 @@ func (p *processor) GetLatestInfoUntilBlock(ctx context.Context, blockNum uint64 if lpb < blockNum { return nil, ErrBlockNotProcessed } - c, err := tx.Cursor(blockTable) + iter, err := tx.RangeDescend(blockTable, uint64ToBytes(blockNum), uint64ToBytes(0), 1) if err != nil { return nil, err } - defer c.Close() - for k, v, err := c.Seek(uint64ToBytes(blockNum)); k != nil; k, v, err = c.Prev() { - if err != nil { - return nil, err - } - if bytes2Uint64(k) > blockNum { - // Seek function returns matching key or greater, therefore - // we could bed ealing with a block number greater than expected - continue - } - blk := blockWithLeafs{} - if err := json.Unmarshal(v, &blk); err != nil { - return nil, err - } - hash, err := tx.GetOne(indexTable, common.Uint32ToBytes(blk.LastIndex-1)) - if err != nil { - return nil, err - } - return p.getInfoByHashWithTx(tx, hash) + if !iter.HasNext() { + return nil, ErrNotFound } - - return nil, ErrNotFound + _, v, err := iter.Next() + if err != nil { + return nil, err + } + blk := blockWithLeafs{} + if err := json.Unmarshal(v, &blk); err != nil { + return nil, err + } + hash, err := tx.GetOne(indexTable, common.Uint32ToBytes(blk.LastIndex-1)) + if err != nil { + return nil, err + } + return p.getInfoByHashWithTx(tx, hash) } func (p *processor) GetInfoByIndex(ctx context.Context, index uint32) (*L1InfoTreeLeaf, error) { @@ -424,6 +420,7 @@ func (p *processor) ProcessBlock(b sync.Block) error { tx.Rollback() return err } + log.Debugf("block %d processed with events: %+v", b.Num, b.Events) return tx.Commit() } From 698f2bdc740f45cf1f55a6baf489a741134d2b85 Mon Sep 17 00:00:00 2001 From: bros Date: Fri, 26 Jul 2024 15:44:35 +0000 Subject: [PATCH 14/18] add TODO --- l1infotreesync/l1infotreesync.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/l1infotreesync/l1infotreesync.go b/l1infotreesync/l1infotreesync.go index 6c8390ef..ed9056bc 100644 --- a/l1infotreesync/l1infotreesync.go +++ b/l1infotreesync/l1infotreesync.go @@ -21,9 +21,10 @@ var ( ) type Config struct { - DBPath string `mapstructure:"DBPath"` - GlobalExitRootAddr common.Address `mapstructure:"GlobalExitRootAddr"` - SyncBlockChunkSize uint64 `mapstructure:"SyncBlockChunkSize"` + DBPath string `mapstructure:"DBPath"` + GlobalExitRootAddr common.Address `mapstructure:"GlobalExitRootAddr"` + SyncBlockChunkSize uint64 `mapstructure:"SyncBlockChunkSize"` + // TODO: BlockFinality doesnt work as per the jsonschema BlockFinality string `jsonschema:"enum=latest,enum=safe, enum=pending, enum=finalized" mapstructure:"BlockFinality"` URLRPCL1 string `mapstructure:"URLRPCL1"` WaitForNewBlocksPeriod types.Duration `mapstructure:"WaitForNewBlocksPeriod"` From d88238bb0ef14032017cd3ca15ff5af23dce04bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Mon, 29 Jul 2024 12:01:50 +0200 Subject: [PATCH 15/18] go mod tidy --- go.sum | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.sum b/go.sum index 41d4b0f0..6b5b219a 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240726101945-d05a885ae884 h1:oXUct6UWuGs15WyCEKipY0Kc0BsCnMzniAz0EIFoPxs= github.com/0xPolygon/cdk-contracts-tooling v0.0.0-20240726101945-d05a885ae884/go.mod h1:mFlcEjsm2YBBsu8atHJ3zyVnwM+Z/fMXpVmIJge+WVU= -github.com/0xPolygon/cdk-data-availability v0.0.8-0.20240712072318-72ae67613cbf h1:VWxVYeDhDURGp8pHR4kq3jwoXRazVHsQLMMIqYsO+Fw= -github.com/0xPolygon/cdk-data-availability v0.0.8-0.20240712072318-72ae67613cbf/go.mod h1:3XkZ0zn0GsvAT01MPQMmukF534CVSFmtrcoK3F/BK6Q= github.com/0xPolygon/cdk-data-availability v0.0.8 h1:bMmOYZ7Ei683y80ric3KzMPXtRGmchAmfjIRzghaHb4= github.com/0xPolygon/cdk-data-availability v0.0.8/go.mod h1:3XkZ0zn0GsvAT01MPQMmukF534CVSFmtrcoK3F/BK6Q= github.com/0xPolygon/cdk-rpc v0.0.0-20240419104226-c0a62ba0f49d h1:sxh6hZ2jF/sxxj2jd5o1vuNNCZjYmn4aRG9SRlVaEFs= From 69d9139f5c6502f648186e6697522910611fcb2e Mon Sep 17 00:00:00 2001 From: Arnau Date: Tue, 30 Jul 2024 17:37:19 +0200 Subject: [PATCH 16/18] Add PR review suggestions from Stefan-Ethernal --- Dockerfile | 2 +- aggoracle/chaingersender/evm.go | 6 +-- aggoracle/oracle.go | 4 +- common/common.go | 10 ++--- l1infotreesync/processor.go | 69 +++++++++++++++++++-------------- sync/evmdownloader.go | 27 ++++++++----- 6 files changed, 68 insertions(+), 50 deletions(-) diff --git a/Dockerfile b/Dockerfile index 18224428..719868f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM golang:1.22.5-alpine3.20 AS build WORKDIR $GOPATH/src/github.com/0xPolygon/cdk -RUN apk update && apk add --no-cache make build-base git +RUN apk update && apk add --no-cache make build-base git # INSTALL DEPENDENCIES COPY go.mod go.sum /src/ RUN cd /src && go mod download diff --git a/aggoracle/chaingersender/evm.go b/aggoracle/chaingersender/evm.go index 42cd49a4..3a4060a4 100644 --- a/aggoracle/chaingersender/evm.go +++ b/aggoracle/chaingersender/evm.go @@ -86,6 +86,9 @@ func (c *EVMChainGERSender) UpdateGERWaitUntilMined(ctx context.Context, ger com return err } data, err := abi.Pack("updateGlobalExitRoot", ger) + if err != nil { + return err + } id, err := c.ethTxMan.Add(ctx, &c.gerAddr, nil, big.NewInt(0), data, c.gasOffset, nil) if err != nil { return err @@ -98,15 +101,12 @@ func (c *EVMChainGERSender) UpdateGERWaitUntilMined(ctx context.Context, ger com } switch res.Status { case ethtxmanager.MonitoredTxStatusCreated: - continue case ethtxmanager.MonitoredTxStatusSent: continue case ethtxmanager.MonitoredTxStatusFailed: return fmt.Errorf("tx %s failed", res.ID) case ethtxmanager.MonitoredTxStatusMined: - return nil case ethtxmanager.MonitoredTxStatusSafe: - return nil case ethtxmanager.MonitoredTxStatusFinalized: return nil default: diff --git a/aggoracle/oracle.go b/aggoracle/oracle.go index 291950c5..175801a6 100644 --- a/aggoracle/oracle.go +++ b/aggoracle/oracle.go @@ -71,10 +71,10 @@ func (a *AggOracle) Start(ctx context.Context) { } continue } - if alreadyInjectd, err := a.chainSender.IsGERAlreadyInjected(gerToInject); err != nil { + if alreadyInjected, err := a.chainSender.IsGERAlreadyInjected(gerToInject); err != nil { log.Error("error calling isGERAlreadyInjected: ", err) continue - } else if alreadyInjectd { + } else if alreadyInjected { log.Debugf("GER %s already injected", gerToInject.Hex()) continue } diff --git a/common/common.go b/common/common.go index d2f440d1..ebbafd69 100644 --- a/common/common.go +++ b/common/common.go @@ -9,27 +9,27 @@ import ( "github.com/iden3/go-iden3-crypto/keccak256" ) -// Uint64To2Bytes converts a block number to a byte slice -func Uint64To2Bytes(num uint64) []byte { +// Uint64ToBytes converts a uint64 to a byte slice +func Uint64ToBytes(num uint64) []byte { bytes := make([]byte, 8) binary.LittleEndian.PutUint64(bytes, num) return bytes } -// BytesToUint64 converts a byte slice to a block number +// BytesToUint64 converts a byte slice to a uint64 func BytesToUint64(bytes []byte) uint64 { return binary.LittleEndian.Uint64(bytes) } -// Uint32To2Bytes converts a block number to a byte slice +// Uint32To2Bytes converts a uint32 to a byte slice func Uint32ToBytes(num uint32) []byte { key := make([]byte, 4) binary.LittleEndian.PutUint32(key, num) return key } -// BytesToUint32 converts a byte slice to a block number +// BytesToUint32 converts a byte slice to a uint32 func BytesToUint32(bytes []byte) uint32 { return binary.LittleEndian.Uint32(bytes) } diff --git a/l1infotreesync/processor.go b/l1infotreesync/processor.go index 2e6116c4..73c48d86 100644 --- a/l1infotreesync/processor.go +++ b/l1infotreesync/processor.go @@ -2,7 +2,6 @@ package l1infotreesync import ( "context" - "encoding/binary" "encoding/json" "errors" @@ -17,10 +16,29 @@ import ( ) const ( - rootTable = "l1infotreesync-root" - indexTable = "l1infotreesync-index" - infoTable = "l1infotreesync-info" - blockTable = "l1infotreesync-block" + // rootTable stores the L1 info tree roots + // Key: root (common.Hash) + // Value: hash of the leaf that caused the update (common.Hash) + rootTable = "l1infotreesync-root" + // indexTable stores the L1 info tree indexes + // Key: index (uint32 converted to bytes) + // Value: hash of the leaf that caused the update (common.Hash) + indexTable = "l1infotreesync-index" + // infoTable stores the information of the tree (the leaves). Note that the value + // of rootTable and indexTable references the key of the infoTable + // Key: hash of the leaf that caused the update (common.Hash) + // Value: JSON of storeLeaf struct + infoTable = "l1infotreesync-info" + // blockTable stores the first and last index of L1 Info Tree that have been updated on + // a block. This is useful in case there are blocks with multiple updates and a reorg is needed. + // Or for when querying by block number + // Key: block number (uint64 converted to bytes) + // Value: JSON of blockWithLeafs + blockTable = "l1infotreesync-block" + // lastBlockTable used to store the last block processed. This is needed to know the last processed blcok + // when it doesn't have events that make other tables get populated + // Key: it's always lastBlockKey + // Value: block number (uint64 converted to bytes) lastBlockTable = "l1infotreesync-lastBlock" treeHeight uint8 = 32 @@ -29,7 +47,7 @@ const ( var ( ErrBlockNotProcessed = errors.New("given block(s) have not been processed yet") ErrNotFound = errors.New("not found") - lastBlokcKey = []byte("lb") + lastBlockKey = []byte("lb") ) type processor struct { @@ -130,7 +148,7 @@ func (p *processor) getAllLeavesHashed(ctx context.Context) ([][32]byte, error) return nil, err } - return p.getHasedLeaves(tx, index) + return p.getHashedLeaves(tx, index) } func (p *processor) ComputeMerkleProofByIndex(ctx context.Context, index uint32) ([][32]byte, ethCommon.Hash, error) { @@ -143,14 +161,14 @@ func (p *processor) ComputeMerkleProofByIndex(ctx context.Context, index uint32) } defer tx.Rollback() - leaves, err := p.getHasedLeaves(tx, index) + leaves, err := p.getHashedLeaves(tx, index) if err != nil { return nil, ethCommon.Hash{}, err } return p.tree.ComputeMerkleProof(index, leaves) } -func (p *processor) getHasedLeaves(tx kv.Tx, untilIndex uint32) ([][32]byte, error) { +func (p *processor) getHashedLeaves(tx kv.Tx, untilIndex uint32) ([][32]byte, error) { leaves := [][32]byte{} for i := uint32(0); i <= untilIndex; i++ { info, err := p.getInfoByIndexWithTx(tx, i) @@ -187,7 +205,7 @@ func (p *processor) GetInfoByRoot(ctx context.Context, root ethCommon.Hash) (*L1 return p.getInfoByHashWithTx(tx, hash) } -// GetLatestInfoUntilBlock returns the most recent L1InfoTreeLeaf that occured before or at blockNum. +// GetLatestInfoUntilBlock returns the most recent L1InfoTreeLeaf that occurred before or at blockNum. // If the blockNum has not been processed yet the error ErrBlockNotProcessed will be returned func (p *processor) GetLatestInfoUntilBlock(ctx context.Context, blockNum uint64) (*L1InfoTreeLeaf, error) { tx, err := p.db.BeginRo(ctx) @@ -196,10 +214,13 @@ func (p *processor) GetLatestInfoUntilBlock(ctx context.Context, blockNum uint64 } defer tx.Rollback() lpb, err := p.getLastProcessedBlockWithTx(tx) + if err != nil { + return nil, err + } if lpb < blockNum { return nil, ErrBlockNotProcessed } - iter, err := tx.RangeDescend(blockTable, uint64ToBytes(blockNum), uint64ToBytes(0), 1) + iter, err := tx.RangeDescend(blockTable, common.Uint64ToBytes(blockNum), common.Uint64ToBytes(0), 1) if err != nil { return nil, err } @@ -285,13 +306,13 @@ func (p *processor) GetLastProcessedBlock(ctx context.Context) (uint64, error) { } func (p *processor) getLastProcessedBlockWithTx(tx kv.Tx) (uint64, error) { - if blockNumBytes, err := tx.GetOne(lastBlockTable, lastBlokcKey); err != nil { + blockNumBytes, err := tx.GetOne(lastBlockTable, lastBlockKey) + if err != nil { return 0, err } else if blockNumBytes == nil { return 0, nil - } else { - return bytes2Uint64(blockNumBytes), nil } + return common.BytesToUint64(blockNumBytes), nil } func (p *processor) Reorg(firstReorgedBlock uint64) error { @@ -305,7 +326,7 @@ func (p *processor) Reorg(firstReorgedBlock uint64) error { return err } defer c.Close() - firstKey := uint64ToBytes(firstReorgedBlock) + firstKey := common.Uint64ToBytes(firstReorgedBlock) for blkKey, blkValue, err := c.Seek(firstKey); blkKey != nil; blkKey, blkValue, err = c.Next() { if err != nil { tx.Rollback() @@ -411,7 +432,7 @@ func (p *processor) ProcessBlock(b sync.Block) error { tx.Rollback() return err } - if err := tx.Put(blockTable, uint64ToBytes(b.Num), blockValue); err != nil { + if err := tx.Put(blockTable, common.Uint64ToBytes(b.Num), blockValue); err != nil { tx.Rollback() return err } @@ -432,7 +453,7 @@ func (p *processor) getLastIndex(tx kv.Tx) (uint32, error) { if bNum == 0 { return 0, nil } - iter, err := tx.RangeDescend(blockTable, uint64ToBytes(bNum), uint64ToBytes(0), 1) + iter, err := tx.RangeDescend(blockTable, common.Uint64ToBytes(bNum), common.Uint64ToBytes(0), 1) if err != nil { return 0, err } @@ -478,16 +499,6 @@ func (p *processor) addLeaf(tx kv.RwTx, leaf storeLeaf) error { } func (p *processor) updateLastProcessedBlock(tx kv.RwTx, blockNum uint64) error { - blockNumBytes := uint64ToBytes(blockNum) - return tx.Put(lastBlockTable, lastBlokcKey, blockNumBytes) -} - -func uint64ToBytes(num uint64) []byte { - key := make([]byte, 8) - binary.LittleEndian.PutUint64(key, num) - return key -} - -func bytes2Uint64(key []byte) uint64 { - return binary.LittleEndian.Uint64(key) + blockNumBytes := common.Uint64ToBytes(blockNum) + return tx.Put(lastBlockTable, lastBlockKey, blockNumBytes) } diff --git a/sync/evmdownloader.go b/sync/evmdownloader.go index e6d9dc8d..ebdde880 100644 --- a/sync/evmdownloader.go +++ b/sync/evmdownloader.go @@ -110,18 +110,25 @@ type downloaderImplementation struct { func (d *downloaderImplementation) waitForNewBlocks(ctx context.Context, lastBlockSeen uint64) (newLastBlock uint64) { attempts := 0 + ticker := time.NewTicker(d.waitForNewBlocksPeriod) + defer ticker.Stop() for { - header, err := d.ethClient.HeaderByNumber(ctx, d.blockFinality) - if err != nil { - attempts++ - log.Error("error geting last block num from eth client: ", err) - RetryHandler("waitForNewBlocks", attempts) - continue - } - if header.Number.Uint64() > lastBlockSeen { - return header.Number.Uint64() + select { + case <-ctx.Done(): + log.Info("context cancelled") + return lastBlockSeen + case <-ticker.C: + header, err := d.ethClient.HeaderByNumber(ctx, d.blockFinality) + if err != nil { + attempts++ + log.Error("error getting last block num from eth client: ", err) + RetryHandler("waitForNewBlocks", attempts) + continue + } + if header.Number.Uint64() > lastBlockSeen { + return header.Number.Uint64() + } } - time.Sleep(d.waitForNewBlocksPeriod) } } From b1a399b254e390efdbf1c94b3324080f894a305d Mon Sep 17 00:00:00 2001 From: Arnau Date: Tue, 30 Jul 2024 18:34:14 +0200 Subject: [PATCH 17/18] fix UTs --- aggoracle/chaingersender/evm.go | 13 +++++---- aggoracle/e2e_test.go | 3 +- aggoracle/oracle.go | 49 +++++++++++++++++++-------------- l1infotreesync/processor.go | 17 ++++++++---- localbridgesync/processor.go | 8 +++--- 5 files changed, 53 insertions(+), 37 deletions(-) diff --git a/aggoracle/chaingersender/evm.go b/aggoracle/chaingersender/evm.go index 3a4060a4..93ce347c 100644 --- a/aggoracle/chaingersender/evm.go +++ b/aggoracle/chaingersender/evm.go @@ -75,7 +75,7 @@ func NewEVMChainGERSender( func (c *EVMChainGERSender) IsGERAlreadyInjected(ger common.Hash) (bool, error) { timestamp, err := c.gerContract.GlobalExitRootMap(&bind.CallOpts{Pending: false}, ger) if err != nil { - return false, err + return false, fmt.Errorf("error calling gerContract.GlobalExitRootMap: %w", err) } return timestamp.Cmp(big.NewInt(0)) != 0, nil } @@ -95,19 +95,20 @@ func (c *EVMChainGERSender) UpdateGERWaitUntilMined(ctx context.Context, ger com } for { time.Sleep(c.waitPeriodMonitorTx) + log.Debugf("waiting for tx %s to be mined", id.Hex()) res, err := c.ethTxMan.Result(ctx, id) if err != nil { log.Error("error calling ethTxMan.Result: ", err) } switch res.Status { - case ethtxmanager.MonitoredTxStatusCreated: - case ethtxmanager.MonitoredTxStatusSent: + case ethtxmanager.MonitoredTxStatusCreated, + ethtxmanager.MonitoredTxStatusSent: continue case ethtxmanager.MonitoredTxStatusFailed: return fmt.Errorf("tx %s failed", res.ID) - case ethtxmanager.MonitoredTxStatusMined: - case ethtxmanager.MonitoredTxStatusSafe: - case ethtxmanager.MonitoredTxStatusFinalized: + case ethtxmanager.MonitoredTxStatusMined, + ethtxmanager.MonitoredTxStatusSafe, + ethtxmanager.MonitoredTxStatusFinalized: return nil default: log.Error("unexpected tx status: ", res.Status) diff --git a/aggoracle/e2e_test.go b/aggoracle/e2e_test.go index ad1ff9c3..3e09c906 100644 --- a/aggoracle/e2e_test.go +++ b/aggoracle/e2e_test.go @@ -3,6 +3,7 @@ package aggoracle_test import ( "context" "errors" + "fmt" "math/big" "strconv" "testing" @@ -208,6 +209,6 @@ func runTest( require.NoError(t, err) isInjected, err := sender.IsGERAlreadyInjected(expectedGER) require.NoError(t, err) - require.True(t, isInjected) + require.True(t, isInjected, fmt.Sprintf("iteration %d, GER: %s", i, common.Bytes2Hex(expectedGER[:]))) } } diff --git a/aggoracle/oracle.go b/aggoracle/oracle.go index 175801a6..49d14b7e 100644 --- a/aggoracle/oracle.go +++ b/aggoracle/oracle.go @@ -9,17 +9,9 @@ import ( "github.com/0xPolygon/cdk/l1infotreesync" "github.com/0xPolygon/cdk/log" "github.com/ethereum/go-ethereum" - "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" ) -type EthClienter interface { - ethereum.LogFilterer - ethereum.BlockNumberReader - ethereum.ChainReader - bind.ContractBackend -} - type L1InfoTreer interface { GetLatestInfoUntilBlock(ctx context.Context, blockNum uint64) (*l1infotreesync.L1InfoTreeLeaf, error) } @@ -31,7 +23,7 @@ type ChainSender interface { type AggOracle struct { ticker *time.Ticker - l1Client EthClienter + l1Client ethereum.ChainReader l1Info L1InfoTreer chainSender ChainSender blockFinality *big.Int @@ -39,7 +31,7 @@ type AggOracle struct { func New( chainSender ChainSender, - l1Client EthClienter, + l1Client ethereum.ChainReader, l1InfoTreeSyncer L1InfoTreer, blockFinalityType etherman.BlockNumberFinality, waitPeriodNextGER time.Duration, @@ -59,15 +51,23 @@ func New( } func (a *AggOracle) Start(ctx context.Context) { + var ( + blockNumToFetch uint64 + gerToInject common.Hash + err error + ) for { select { case <-a.ticker.C: - gerToInject, err := a.getLastFinalisedGER(ctx) + blockNumToFetch, gerToInject, err = a.getLastFinalisedGER(ctx, blockNumToFetch) if err != nil { - if err == l1infotreesync.ErrBlockNotProcessed || err == l1infotreesync.ErrNotFound { - log.Debugf("syncer is not ready: %v", err) + if err == l1infotreesync.ErrBlockNotProcessed { + log.Debugf("syncer is not ready for the block %d", blockNumToFetch) + } else if err == l1infotreesync.ErrNotFound { + blockNumToFetch = 0 + log.Debugf("syncer has not found any GER until block %d", blockNumToFetch) } else { - log.Error("error calling isGERAlreadyInjected: ", err) + log.Error("error calling getLastFinalisedGER: ", err) } continue } @@ -90,14 +90,21 @@ func (a *AggOracle) Start(ctx context.Context) { } } -func (a *AggOracle) getLastFinalisedGER(ctx context.Context) (common.Hash, error) { - header, err := a.l1Client.HeaderByNumber(ctx, a.blockFinality) - if err != nil { - return common.Hash{}, err +// getLastFinalisedGER tries to return a finalised GER: +// If blockNumToFetch != 0: it will try to fetch it until the given block +// Else it will ask the L1 client for the latest finalised block and use that +// If it fails to get the GER from the syncer, it will retunr the block number that used to query +func (a *AggOracle) getLastFinalisedGER(ctx context.Context, blockNumToFetch uint64) (uint64, common.Hash, error) { + if blockNumToFetch == 0 { + header, err := a.l1Client.HeaderByNumber(ctx, a.blockFinality) + if err != nil { + return 0, common.Hash{}, err + } + blockNumToFetch = header.Number.Uint64() } - info, err := a.l1Info.GetLatestInfoUntilBlock(ctx, header.Number.Uint64()) + info, err := a.l1Info.GetLatestInfoUntilBlock(ctx, blockNumToFetch) if err != nil { - return common.Hash{}, err + return blockNumToFetch, common.Hash{}, err } - return info.GlobalExitRoot, nil + return 0, info.GlobalExitRoot, nil } diff --git a/l1infotreesync/processor.go b/l1infotreesync/processor.go index 73c48d86..9b444d43 100644 --- a/l1infotreesync/processor.go +++ b/l1infotreesync/processor.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "errors" + "fmt" "github.com/0xPolygon/cdk/common" "github.com/0xPolygon/cdk/l1infotree" @@ -47,6 +48,7 @@ const ( var ( ErrBlockNotProcessed = errors.New("given block(s) have not been processed yet") ErrNotFound = errors.New("not found") + ErrNoBlock0 = errors.New("blockNum must be greater than 0") lastBlockKey = []byte("lb") ) @@ -208,6 +210,9 @@ func (p *processor) GetInfoByRoot(ctx context.Context, root ethCommon.Hash) (*L1 // GetLatestInfoUntilBlock returns the most recent L1InfoTreeLeaf that occurred before or at blockNum. // If the blockNum has not been processed yet the error ErrBlockNotProcessed will be returned func (p *processor) GetLatestInfoUntilBlock(ctx context.Context, blockNum uint64) (*L1InfoTreeLeaf, error) { + if blockNum == 0 { + return nil, ErrNoBlock0 + } tx, err := p.db.BeginRo(ctx) if err != nil { return nil, err @@ -222,15 +227,17 @@ func (p *processor) GetLatestInfoUntilBlock(ctx context.Context, blockNum uint64 } iter, err := tx.RangeDescend(blockTable, common.Uint64ToBytes(blockNum), common.Uint64ToBytes(0), 1) if err != nil { - return nil, err - } - if !iter.HasNext() { - return nil, ErrNotFound + return nil, fmt.Errorf( + "error calling RangeDescend(blockTable, %d, 0, 1): %w", blockNum, err, + ) } - _, v, err := iter.Next() + k, v, err := iter.Next() if err != nil { return nil, err } + if k == nil { + return nil, ErrNotFound + } blk := blockWithLeafs{} if err := json.Unmarshal(v, &blk); err != nil { return nil, err diff --git a/localbridgesync/processor.go b/localbridgesync/processor.go index 4a45c663..5d644a9a 100644 --- a/localbridgesync/processor.go +++ b/localbridgesync/processor.go @@ -96,7 +96,7 @@ func (p *processor) GetClaimsAndBridges( } defer c.Close() - for k, v, err := c.Seek(common.Uint64To2Bytes(fromBlock)); k != nil; k, v, err = c.Next() { + for k, v, err := c.Seek(common.Uint64ToBytes(fromBlock)); k != nil; k, v, err = c.Next() { if err != nil { return nil, err } @@ -143,7 +143,7 @@ func (p *processor) Reorg(firstReorgedBlock uint64) error { return err } defer c.Close() - firstKey := common.Uint64To2Bytes(firstReorgedBlock) + firstKey := common.Uint64ToBytes(firstReorgedBlock) for k, _, err := c.Seek(firstKey); k != nil; k, _, err = c.Next() { if err != nil { tx.Rollback() @@ -176,7 +176,7 @@ func (p *processor) ProcessBlock(block sync.Block) error { tx.Rollback() return err } - if err := tx.Put(eventsTable, common.Uint64To2Bytes(block.Num), value); err != nil { + if err := tx.Put(eventsTable, common.Uint64ToBytes(block.Num), value); err != nil { tx.Rollback() return err } @@ -189,6 +189,6 @@ func (p *processor) ProcessBlock(block sync.Block) error { } func (p *processor) updateLastProcessedBlock(tx kv.RwTx, blockNum uint64) error { - blockNumBytes := common.Uint64To2Bytes(blockNum) + blockNumBytes := common.Uint64ToBytes(blockNum) return tx.Put(lastBlockTable, lastBlokcKey, blockNumBytes) } From 5f2c29ffc82273a027c703649b21c216ac214358 Mon Sep 17 00:00:00 2001 From: Arnau Date: Thu, 1 Aug 2024 10:23:09 +0200 Subject: [PATCH 18/18] Add PR review suggestions from joanestebanr --- aggoracle/chaingersender/evm.go | 14 +++++----- aggoracle/e2e_test.go | 2 +- aggoracle/oracle.go | 4 +-- cmd/run.go | 4 ++- config/default.go | 45 ++++++++++++++++++++++++++++++ l1infotreesync/e2e_test.go | 2 +- l1infotreesync/l1infotreesync.go | 28 +++++++++++-------- l1infotreesync/processor.go | 32 ++++++++++++++------- localbridgesync/localbridgesync.go | 7 ++++- sync/common.go | 16 +++++------ sync/evmdownloader.go | 11 +++++--- sync/evmdownloader_test.go | 8 ++++-- sync/evmdriver.go | 11 +++++--- sync/evmdriver_test.go | 21 ++++++++++---- 14 files changed, 145 insertions(+), 60 deletions(-) diff --git a/aggoracle/chaingersender/evm.go b/aggoracle/chaingersender/evm.go index 93ce347c..859f4b8b 100644 --- a/aggoracle/chaingersender/evm.go +++ b/aggoracle/chaingersender/evm.go @@ -41,13 +41,13 @@ type EVMChainGERSender struct { } type EVMConfig struct { - GlobalExitRootL2 common.Address `mapstructure:"GlobalExitRootL2"` - URLRPCL2 string `mapstructure:"URLRPCL2"` - ChainIDL2 uint64 `mapstructure:"ChainIDL2"` - GasOffset uint64 `mapstructure:"GasOffset"` - WaitPeriodMonitorTx cfgTypes.Duration `mapstructure:"WaitPeriodMonitorTx"` - SenderAddr common.Address `mapstructure:"SenderAddr"` - EthTxManager ethtxmanager.Config `mapstructure:"EthTxManager"` + GlobalExitRootL2Addr common.Address `mapstructure:"GlobalExitRootL2"` + URLRPCL2 string `mapstructure:"URLRPCL2"` + ChainIDL2 uint64 `mapstructure:"ChainIDL2"` + GasOffset uint64 `mapstructure:"GasOffset"` + WaitPeriodMonitorTx cfgTypes.Duration `mapstructure:"WaitPeriodMonitorTx"` + SenderAddr common.Address `mapstructure:"SenderAddr"` + EthTxManager ethtxmanager.Config `mapstructure:"EthTxManager"` } func NewEVMChainGERSender( diff --git a/aggoracle/e2e_test.go b/aggoracle/e2e_test.go index 3e09c906..ce081c35 100644 --- a/aggoracle/e2e_test.go +++ b/aggoracle/e2e_test.go @@ -60,7 +60,7 @@ func commonSetup(t *testing.T) ( require.NoError(t, err) // Syncer dbPathSyncer := t.TempDir() - syncer, err := l1infotreesync.New(ctx, dbPathSyncer, gerL1Addr, 10, etherman.LatestBlock, reorg, l1Client.Client(), time.Millisecond, 0) + syncer, err := l1infotreesync.New(ctx, dbPathSyncer, gerL1Addr, 10, etherman.LatestBlock, reorg, l1Client.Client(), time.Millisecond, 0, 100*time.Millisecond, 3) require.NoError(t, err) go syncer.Start(ctx) diff --git a/aggoracle/oracle.go b/aggoracle/oracle.go index 49d14b7e..f22ee1f0 100644 --- a/aggoracle/oracle.go +++ b/aggoracle/oracle.go @@ -78,12 +78,12 @@ func (a *AggOracle) Start(ctx context.Context) { log.Debugf("GER %s already injected", gerToInject.Hex()) continue } - log.Debugf("injecting new GER: %s", gerToInject.Hex()) + log.Infof("injecting new GER: %s", gerToInject.Hex()) if err := a.chainSender.UpdateGERWaitUntilMined(ctx, gerToInject); err != nil { log.Errorf("error calling updateGERWaitUntilMined, when trying to inject GER %s: %v", gerToInject.Hex(), err) continue } - log.Debugf("GER %s injected", gerToInject.Hex()) + log.Infof("GER %s injected", gerToInject.Hex()) case <-ctx.Done(): return } diff --git a/cmd/run.go b/cmd/run.go index 4bb24fc4..f7d36b74 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -217,7 +217,7 @@ func createAggoracle(cfg config.Config, l1Client *ethclient.Client, syncer *l1in log.Fatal(err) } sender, err = chaingersender.NewEVMChainGERSender( - cfg.AggOracle.EVMSender.GlobalExitRootL2, + cfg.AggOracle.EVMSender.GlobalExitRootL2Addr, cfg.AggOracle.EVMSender.SenderAddr, l2CLient, ethTxManager, @@ -388,6 +388,8 @@ func newL1InfoTreeSyncer( l1Client, cfg.L1InfoTreeSync.WaitForNewBlocksPeriod.Duration, cfg.L1InfoTreeSync.InitialBlock, + cfg.L1InfoTreeSync.RetryAfterErrorPeriod.Duration, + cfg.L1InfoTreeSync.MaxRetryAttemptsAfterError, ) if err != nil { log.Fatal(err) diff --git a/config/default.go b/config/default.go index 7b12e6f3..85dbd1cd 100644 --- a/config/default.go +++ b/config/default.go @@ -118,4 +118,49 @@ SequencerPrivateKey = {} [Aggregator.Synchronizer.Etherman] [Aggregator.Synchronizer.Etherman.Validium] Enabled = false + +[ReorgDetectorL1] +DBPath = "/tmp/reorgdetector" + +[L1InfoTreeSync] +DBPath = "/tmp/L1InfoTreeSync" +GlobalExitRootAddr="0x8464135c8F25Da09e49BC8782676a84730C318bC" +SyncBlockChunkSize=10 +BlockFinality="latest" +URLRPCL1="http://test-aggoracle-l1:8545" +WaitForNewBlocksPeriod="100ms" +InitialBlock=0 + +[AggOracle] +TargetChainType="EVM" +URLRPCL1="http://test-aggoracle-l1:8545" +BlockFinality="latest" +WaitPeriodNextGER="100ms" + [EVMSender] + GlobalExitRootL2="0x8464135c8F25Da09e49BC8782676a84730C318bC" + URLRPCL2="http://test-aggoracle-l2:8545" + ChainIDL2=1337 + GasOffset=0 + WaitPeriodMonitorTx="100ms" + SenderAddr="0x70997970c51812dc3a010c7d01b50e0d17dc79c8" + [SequenceSender.EthTxManager] + FrequencyToMonitorTxs = "1s" + WaitTxToBeMined = "2s" + GetReceiptMaxTime = "250ms" + GetReceiptWaitInterval = "1s" + PrivateKeys = [ + {Path = "/app/keystore/aggoracle.keystore", Password = "testonly"}, + ] + ForcedGas = 0 + GasPriceMarginFactor = 1 + MaxGasPriceLimit = 0 + PersistenceFilename = "/tmp/ethtxmanager.json" + ReadPendingL1Txs = false + SafeStatusL1NumberOfBlocks = 5 + FinalizedStatusL1NumberOfBlocks = 10 + [SequenceSender.EthTxManager.Etherman] + URL = "http://test-aggoracle-l2" + MultiGasProvider = false + L1ChainID = 1337 + HTTPHeaders = [] ` diff --git a/l1infotreesync/e2e_test.go b/l1infotreesync/e2e_test.go index 35958f08..82bef733 100644 --- a/l1infotreesync/e2e_test.go +++ b/l1infotreesync/e2e_test.go @@ -54,7 +54,7 @@ func TestE2E(t *testing.T) { rdm.On("AddBlockToTrack", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) client, gerAddr, gerSc, err := newSimulatedClient(auth) require.NoError(t, err) - syncer, err := New(ctx, dbPath, gerAddr, 10, etherman.LatestBlock, rdm, client.Client(), time.Millisecond, 0) + syncer, err := New(ctx, dbPath, gerAddr, 10, etherman.LatestBlock, rdm, client.Client(), time.Millisecond, 0, 100*time.Millisecond, 3) require.NoError(t, err) go syncer.Start(ctx) diff --git a/l1infotreesync/l1infotreesync.go b/l1infotreesync/l1infotreesync.go index ed9056bc..7b3be753 100644 --- a/l1infotreesync/l1infotreesync.go +++ b/l1infotreesync/l1infotreesync.go @@ -15,20 +15,17 @@ const ( downloadBufferSize = 1000 ) -var ( - retryAfterErrorPeriod = time.Second * 10 - maxRetryAttemptsAfterError = 5 -) - type Config struct { DBPath string `mapstructure:"DBPath"` GlobalExitRootAddr common.Address `mapstructure:"GlobalExitRootAddr"` SyncBlockChunkSize uint64 `mapstructure:"SyncBlockChunkSize"` // TODO: BlockFinality doesnt work as per the jsonschema - BlockFinality string `jsonschema:"enum=latest,enum=safe, enum=pending, enum=finalized" mapstructure:"BlockFinality"` - URLRPCL1 string `mapstructure:"URLRPCL1"` - WaitForNewBlocksPeriod types.Duration `mapstructure:"WaitForNewBlocksPeriod"` - InitialBlock uint64 `mapstructure:"InitialBlock"` + BlockFinality string `jsonschema:"enum=latest,enum=safe, enum=pending, enum=finalized" mapstructure:"BlockFinality"` + URLRPCL1 string `mapstructure:"URLRPCL1"` + WaitForNewBlocksPeriod types.Duration `mapstructure:"WaitForNewBlocksPeriod"` + InitialBlock uint64 `mapstructure:"InitialBlock"` + RetryAfterErrorPeriod types.Duration `mapstructure:"RetryAfterErrorPeriod"` + MaxRetryAttemptsAfterError int `mapstructure:"MaxRetryAttemptsAfterError"` } type L1InfoTreeSync struct { @@ -46,6 +43,8 @@ func New( l1Client EthClienter, waitForNewBlocksPeriod time.Duration, initialBlock uint64, + retryAfterErrorPeriod time.Duration, + maxRetryAttemptsAfterError int, ) (*L1InfoTreeSync, error) { processor, err := newProcessor(ctx, dbPath) if err != nil { @@ -56,14 +55,18 @@ func New( if err != nil { return nil, err } - if lastProcessedBlock < initialBlock { + if initialBlock > 0 && lastProcessedBlock < initialBlock-1 { err = processor.ProcessBlock(sync.Block{ - Num: initialBlock, + Num: initialBlock - 1, }) if err != nil { return nil, err } } + rh := &sync.RetryHandler{ + RetryAfterErrorPeriod: retryAfterErrorPeriod, + MaxRetryAttemptsAfterError: maxRetryAttemptsAfterError, + } appender, err := buildAppender(l1Client, globalExitRoot) if err != nil { @@ -76,12 +79,13 @@ func New( waitForNewBlocksPeriod, appender, []common.Address{globalExitRoot}, + rh, ) if err != nil { return nil, err } - driver, err := sync.NewEVMDriver(rd, processor, downloader, reorgDetectorID, downloadBufferSize) + driver, err := sync.NewEVMDriver(rd, processor, downloader, reorgDetectorID, downloadBufferSize, rh) if err != nil { return nil, err } diff --git a/l1infotreesync/processor.go b/l1infotreesync/processor.go index 9b444d43..35191062 100644 --- a/l1infotreesync/processor.go +++ b/l1infotreesync/processor.go @@ -122,7 +122,13 @@ func newProcessor(ctx context.Context, dbPath string) (*processor, error) { p := &processor{ db: db, } - leaves, err := p.getAllLeavesHashed(ctx) + + tx, err := p.db.BeginRo(ctx) + if err != nil { + return nil, err + } + defer tx.Rollback() + leaves, err := p.getAllLeavesHashed(tx) if err != nil { return nil, err } @@ -134,14 +140,8 @@ func newProcessor(ctx context.Context, dbPath string) (*processor, error) { return p, nil } -func (p *processor) getAllLeavesHashed(ctx context.Context) ([][32]byte, error) { +func (p *processor) getAllLeavesHashed(tx kv.Tx) ([][32]byte, error) { // TODO: same coment about refactor that appears at ComputeMerkleProofByIndex - tx, err := p.db.BeginRo(ctx) - if err != nil { - return nil, err - } - defer tx.Rollback() - index, err := p.getLastIndex(tx) if err == ErrNotFound || index == 0 { return nil, nil @@ -323,7 +323,6 @@ func (p *processor) getLastProcessedBlockWithTx(tx kv.Tx) (uint64, error) { } func (p *processor) Reorg(firstReorgedBlock uint64) error { - // TODO: Does tree need to be reorged? tx, err := p.db.BeginRw(context.Background()) if err != nil { return err @@ -359,6 +358,17 @@ func (p *processor) Reorg(firstReorgedBlock uint64) error { tx.Rollback() return err } + leaves, err := p.getAllLeavesHashed(tx) + if err != nil { + tx.Rollback() + return err + } + tree, err := l1infotree.NewL1InfoTree(treeHeight, leaves) + if err != nil { + tx.Rollback() + return err + } + p.tree = tree return tx.Commit() } @@ -404,6 +414,7 @@ func (p *processor) ProcessBlock(b sync.Block) error { if err != nil { return err } + events := make([]Event, len(b.Events)) if len(b.Events) > 0 { var initialIndex uint32 lastIndex, err := p.getLastIndex(tx) @@ -417,6 +428,7 @@ func (p *processor) ProcessBlock(b sync.Block) error { } for i, e := range b.Events { event := e.(Event) + events = append(events, event) leafToStore := storeLeaf{ Index: initialIndex + uint32(i), MainnetExitRoot: event.MainnetExitRoot, @@ -448,7 +460,7 @@ func (p *processor) ProcessBlock(b sync.Block) error { tx.Rollback() return err } - log.Debugf("block %d processed with events: %+v", b.Num, b.Events) + log.Debugf("block %d processed with events: %+v", b.Num, events) return tx.Commit() } diff --git a/localbridgesync/localbridgesync.go b/localbridgesync/localbridgesync.go index d0617584..94e60b59 100644 --- a/localbridgesync/localbridgesync.go +++ b/localbridgesync/localbridgesync.go @@ -50,6 +50,10 @@ func New( return nil, err } } + rh := &sync.RetryHandler{ + MaxRetryAttemptsAfterError: maxRetryAttemptsAfterError, + RetryAfterErrorPeriod: retryAfterErrorPeriod, + } appender, err := buildAppender(l2Client, bridge) if err != nil { @@ -62,12 +66,13 @@ func New( waitForNewBlocksPeriod, appender, []common.Address{bridge}, + rh, ) if err != nil { return nil, err } - driver, err := sync.NewEVMDriver(rd, processor, downloader, reorgDetectorID, downloadBufferSize) + driver, err := sync.NewEVMDriver(rd, processor, downloader, reorgDetectorID, downloadBufferSize, rh) if err != nil { return nil, err } diff --git a/sync/common.go b/sync/common.go index 6d1011f5..4fe049d5 100644 --- a/sync/common.go +++ b/sync/common.go @@ -5,17 +5,17 @@ import ( "time" ) -var ( - RetryAfterErrorPeriod = time.Second * 10 - MaxRetryAttemptsAfterError = 5 -) +type RetryHandler struct { + RetryAfterErrorPeriod time.Duration + MaxRetryAttemptsAfterError int +} -func RetryHandler(funcName string, attempts int) { - if attempts >= MaxRetryAttemptsAfterError { +func (h *RetryHandler) Handle(funcName string, attempts int) { + if h.MaxRetryAttemptsAfterError > -1 && attempts >= h.MaxRetryAttemptsAfterError { log.Fatalf( "%s failed too many times (%d)", - funcName, MaxRetryAttemptsAfterError, + funcName, h.MaxRetryAttemptsAfterError, ) } - time.Sleep(RetryAfterErrorPeriod) + time.Sleep(h.RetryAfterErrorPeriod) } diff --git a/sync/evmdownloader.go b/sync/evmdownloader.go index ebdde880..ad452856 100644 --- a/sync/evmdownloader.go +++ b/sync/evmdownloader.go @@ -41,6 +41,7 @@ func NewEVMDownloader( waitForNewBlocksPeriod time.Duration, appender LogAppenderMap, adressessToQuery []common.Address, + rh *RetryHandler, ) (*EVMDownloader, error) { finality, err := blockFinalityType.ToBlockNum() if err != nil { @@ -59,6 +60,7 @@ func NewEVMDownloader( appender: appender, topicsToQuery: topicsToQuery, adressessToQuery: adressessToQuery, + rh: rh, }, }, nil } @@ -106,6 +108,7 @@ type downloaderImplementation struct { appender LogAppenderMap topicsToQuery [][]common.Hash adressessToQuery []common.Address + rh *RetryHandler } func (d *downloaderImplementation) waitForNewBlocks(ctx context.Context, lastBlockSeen uint64) (newLastBlock uint64) { @@ -122,7 +125,7 @@ func (d *downloaderImplementation) waitForNewBlocks(ctx context.Context, lastBlo if err != nil { attempts++ log.Error("error getting last block num from eth client: ", err) - RetryHandler("waitForNewBlocks", attempts) + d.rh.Handle("waitForNewBlocks", attempts) continue } if header.Number.Uint64() > lastBlockSeen { @@ -155,7 +158,7 @@ func (d *downloaderImplementation) getEventsByBlockRange(ctx context.Context, fr if err != nil { attempts++ log.Error("error trying to append log: ", err) - RetryHandler("getLogs", attempts) + d.rh.Handle("getLogs", attempts) continue } break @@ -178,7 +181,7 @@ func (d *downloaderImplementation) getLogs(ctx context.Context, fromBlock, toBlo if err != nil { attempts++ log.Error("error calling FilterLogs to eth client: ", err) - RetryHandler("getLogs", attempts) + d.rh.Handle("getLogs", attempts) continue } return logs @@ -192,7 +195,7 @@ func (d *downloaderImplementation) getBlockHeader(ctx context.Context, blockNum if err != nil { attempts++ log.Errorf("error getting block header for block %d, err: %v", blockNum, err) - RetryHandler("getBlockHeader", attempts) + d.rh.Handle("getBlockHeader", attempts) continue } return EVMBlockHeader{ diff --git a/sync/evmdownloader_test.go b/sync/evmdownloader_test.go index c733aabd..2f5a7ee5 100644 --- a/sync/evmdownloader_test.go +++ b/sync/evmdownloader_test.go @@ -320,7 +320,6 @@ func TestDownload(t *testing.T) { } func TestWaitForNewBlocks(t *testing.T) { - RetryAfterErrorPeriod = time.Millisecond * 100 ctx := context.Background() d, clientMock := NewTestDownloader(t) @@ -353,7 +352,6 @@ func TestWaitForNewBlocks(t *testing.T) { } func TestGetBlockHeader(t *testing.T) { - RetryAfterErrorPeriod = time.Millisecond * 100 ctx := context.Background() d, clientMock := NewTestDownloader(t) @@ -389,8 +387,12 @@ func buildAppender() LogAppenderMap { } func NewTestDownloader(t *testing.T) (*EVMDownloader, *L2Mock) { + rh := &RetryHandler{ + MaxRetryAttemptsAfterError: 5, + RetryAfterErrorPeriod: time.Millisecond * 100, + } clientMock := NewL2Mock(t) - d, err := NewEVMDownloader(clientMock, syncBlockChunck, etherman.LatestBlock, time.Millisecond, buildAppender(), []common.Address{contractAddr}) + d, err := NewEVMDownloader(clientMock, syncBlockChunck, etherman.LatestBlock, time.Millisecond, buildAppender(), []common.Address{contractAddr}, rh) require.NoError(t, err) return d, clientMock } diff --git a/sync/evmdriver.go b/sync/evmdriver.go index a30b96d6..0e20731f 100644 --- a/sync/evmdriver.go +++ b/sync/evmdriver.go @@ -20,6 +20,7 @@ type EVMDriver struct { downloader evmDownloaderFull reorgDetectorID string downloadBufferSize int + rh *RetryHandler } type processorInterface interface { @@ -39,6 +40,7 @@ func NewEVMDriver( downloader evmDownloaderFull, reorgDetectorID string, downloadBufferSize int, + rh *RetryHandler, ) (*EVMDriver, error) { reorgSub, err := reorgDetector.Subscribe(reorgDetectorID) if err != nil { @@ -51,6 +53,7 @@ func NewEVMDriver( downloader: downloader, reorgDetectorID: reorgDetectorID, downloadBufferSize: downloadBufferSize, + rh: rh, }, nil } @@ -66,7 +69,7 @@ reset: if err != nil { attempts++ log.Error("error geting last processed block: ", err) - RetryHandler("Sync", attempts) + d.rh.Handle("Sync", attempts) continue } break @@ -98,7 +101,7 @@ func (d *EVMDriver) handleNewBlock(ctx context.Context, b EVMBlock) { if err != nil { attempts++ log.Errorf("error adding block %d to tracker: %v", b.Num, err) - RetryHandler("handleNewBlock", attempts) + d.rh.Handle("handleNewBlock", attempts) continue } break @@ -113,7 +116,7 @@ func (d *EVMDriver) handleNewBlock(ctx context.Context, b EVMBlock) { if err != nil { attempts++ log.Errorf("error processing events for blcok %d, err: ", b.Num, err) - RetryHandler("handleNewBlock", attempts) + d.rh.Handle("handleNewBlock", attempts) continue } break @@ -139,7 +142,7 @@ func (d *EVMDriver) handleReorg( "error processing reorg, last valid Block %d, err: %v", firstReorgedBlock, err, ) - RetryHandler("handleReorg", attempts) + d.rh.Handle("handleReorg", attempts) continue } break diff --git a/sync/evmdriver_test.go b/sync/evmdriver_test.go index 502722f6..853dda81 100644 --- a/sync/evmdriver_test.go +++ b/sync/evmdriver_test.go @@ -19,7 +19,10 @@ var ( ) func TestSync(t *testing.T) { - RetryAfterErrorPeriod = time.Millisecond * 100 + rh := &RetryHandler{ + MaxRetryAttemptsAfterError: 5, + RetryAfterErrorPeriod: time.Millisecond * 100, + } rdm := NewReorgDetectorMock(t) pm := NewProcessorMock(t) dm := NewEVMDownloaderMock(t) @@ -29,7 +32,7 @@ func TestSync(t *testing.T) { FirstReorgedBlock: firstReorgedBlock, ReorgProcessed: reorgProcessed, }, nil) - driver, err := NewEVMDriver(rdm, pm, dm, reorgDetectorID, 10) + driver, err := NewEVMDriver(rdm, pm, dm, reorgDetectorID, 10, rh) require.NoError(t, err) ctx := context.Background() expectedBlock1 := EVMBlock{ @@ -107,12 +110,15 @@ func TestSync(t *testing.T) { } func TestHandleNewBlock(t *testing.T) { - RetryAfterErrorPeriod = time.Millisecond * 100 + rh := &RetryHandler{ + MaxRetryAttemptsAfterError: 5, + RetryAfterErrorPeriod: time.Millisecond * 100, + } rdm := NewReorgDetectorMock(t) pm := NewProcessorMock(t) dm := NewEVMDownloaderMock(t) rdm.On("Subscribe", reorgDetectorID).Return(&reorgdetector.Subscription{}, nil) - driver, err := NewEVMDriver(rdm, pm, dm, reorgDetectorID, 10) + driver, err := NewEVMDriver(rdm, pm, dm, reorgDetectorID, 10, rh) require.NoError(t, err) ctx := context.Background() @@ -166,7 +172,10 @@ func TestHandleNewBlock(t *testing.T) { } func TestHandleReorg(t *testing.T) { - RetryAfterErrorPeriod = time.Millisecond * 100 + rh := &RetryHandler{ + MaxRetryAttemptsAfterError: 5, + RetryAfterErrorPeriod: time.Millisecond * 100, + } rdm := NewReorgDetectorMock(t) pm := NewProcessorMock(t) dm := NewEVMDownloaderMock(t) @@ -174,7 +183,7 @@ func TestHandleReorg(t *testing.T) { rdm.On("Subscribe", reorgDetectorID).Return(&reorgdetector.Subscription{ ReorgProcessed: reorgProcessed, }, nil) - driver, err := NewEVMDriver(rdm, pm, dm, reorgDetectorID, 10) + driver, err := NewEVMDriver(rdm, pm, dm, reorgDetectorID, 10, rh) require.NoError(t, err) ctx := context.Background()