Skip to content

Commit

Permalink
tool mvp (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
ToniRamirezM authored Sep 5, 2023
1 parent b573c00 commit 4c0f9e4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion datastreamer/streamfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tool/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions tool/config/tool.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ Host = "localhost"
Port = "5432"
EnableLog = false
MaxConns = 200

[Log]
Environment = "development"
Level = "info"
Outputs = ["stdout"]
33 changes: 30 additions & 3 deletions tool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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()
Expand Down

0 comments on commit 4c0f9e4

Please sign in to comment.