From 4c0f9e471a6fbad1ab2181f727e039781d0957d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20Ram=C3=ADrez?= <58293609+ToniRamirezM@users.noreply.github.com> Date: Tue, 5 Sep 2023 11:41:14 +0200 Subject: [PATCH] tool mvp (#5) --- datastreamer/streamfile.go | 2 +- tool/config/config.go | 1 + tool/config/tool.config.toml | 5 +++++ tool/main.go | 33 ++++++++++++++++++++++++++++++--- 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/datastreamer/streamfile.go b/datastreamer/streamfile.go index ae71c7f..79ce4cb 100644 --- a/datastreamer/streamfile.go +++ b/datastreamer/streamfile.go @@ -16,7 +16,7 @@ const ( headerSize = 29 // Header data size pageHeaderSize = 4096 // 4K size header page pageSize = 1024 * 1024 // 1 MB size data page - initPages = 8 // Initial number of data pages + initPages = 80 // Initial number of data pages nextPages = 8 // Number of data pages to add when file is full // Is Entry values diff --git a/tool/config/config.go b/tool/config/config.go index 242d57c..e734ca1 100644 --- a/tool/config/config.go +++ b/tool/config/config.go @@ -23,6 +23,7 @@ const ( type Config struct { StreamServer datastreamer.Config `mapstructure:"StreamServer"` StateDB db.Config `mapstructure:"StateDB"` + LogConfig log.Config `mapstructure:"Log"` } // Default parses the default configuration values. diff --git a/tool/config/tool.config.toml b/tool/config/tool.config.toml index 518f702..bc847a2 100644 --- a/tool/config/tool.config.toml +++ b/tool/config/tool.config.toml @@ -11,3 +11,8 @@ Host = "localhost" Port = "5432" EnableLog = false MaxConns = 200 + +[Log] +Environment = "development" +Level = "info" +Outputs = ["stdout"] diff --git a/tool/main.go b/tool/main.go index 5621574..0bc882a 100644 --- a/tool/main.go +++ b/tool/main.go @@ -66,6 +66,8 @@ func start(cliCtx *cli.Context) error { } log.Infof("Loaded configuration: %+v", c) + // Init logger + log.Init(c.LogConfig) log.Info("Starting tool") // Create a stream server @@ -84,10 +86,35 @@ func start(cliCtx *cli.Context) error { log.Info("Connected to the database") var l2blocks []*db.L2Block + + // Get Genesis block + l2blocks, err = stateDB.GetL2Blocks(cliCtx.Context, 1, 0) + if err != nil { + log.Fatal(err) + } + + err = streamServer.StartStreamTx() + if err != nil { + log.Fatal(err) + } + + _, err = streamServer.AddStreamEntry(1, l2blocks[0].Encode()) + if err != nil { + log.Fatal(err) + } + + err = streamServer.CommitStreamTx() + if err != nil { + log.Fatal(err) + } + var limit uint = 1000 - var offset uint = 0 + var offset uint = 1 + var entry uint64 for err == nil { + log.Infof("Current entry number: %d", entry) + l2blocks, err = stateDB.GetL2Blocks(cliCtx.Context, limit, offset) offset += limit if len(l2blocks) == 0 { @@ -111,12 +138,12 @@ func start(cliCtx *cli.Context) error { } if l2Transactions[x].BlockNum == l2block.BlockNum { - _, err = streamServer.AddStreamEntry(2, l2Transactions[x].Encode()) + entry, err = streamServer.AddStreamEntry(2, l2Transactions[x].Encode()) if err != nil { log.Fatal(err) } } else { - log.Fatal("Mismatch between l2 block and transaction") + log.Fatalf("Mismatch between l2 block and transaction: %d != %d", l2Transactions[x].BlockNum, l2block.BlockNum) } } err = streamServer.CommitStreamTx()