Skip to content

Commit

Permalink
[BLOCK-2572] add reader for new block log
Browse files Browse the repository at this point in the history
  • Loading branch information
Duncan-Ultra committed Nov 7, 2024
1 parent 33e6b93 commit 4492aca
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions codec/consolereader.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ func (l *ConsoleReader) Read() (out interface{}, err error) {
case strings.HasPrefix(line, "DTRX_OP FAILED"):
err = ctx.readFailedDTrxOp(line)

case strings.HasPrefix(line, "ACCEPTED_BLOCK_V2"):
block, err := ctx.readAcceptedBlockV2(line)
if err != nil {
return nil, l.formatError(line, err)
}

return block, nil

case strings.HasPrefix(line, "ACCEPTED_BLOCK"):
block, err := ctx.readAcceptedBlock(line)
if err != nil {
Expand Down Expand Up @@ -503,6 +511,46 @@ func (ctx *parseCtx) readAcceptedBlock(line string) (*pbcodec.Block, error) {
return block, nil
}

// Line format:
//
// ACCEPTED_BLOCK_V2 ${id} ${block_num} ${lib} ${block_state_hex}
func (ctx *parseCtx) readAcceptedBlockV2(line string) (*pbcodec.Block, error) {
chunks := strings.SplitN(line, " ", 8)
if len(chunks) != 8 {
return nil, fmt.Errorf("expected 8 fields, got %d", len(chunks))
}

blockNum, err := strconv.ParseInt(chunks[2], 10, 64)
if err != nil {
return nil, fmt.Errorf("block_num not a valid string, got: %q", chunks[2])
}

if ctx.activeBlockNum != blockNum {
return nil, fmt.Errorf("block_num %d doesn't match the active block num (%d)", blockNum, ctx.activeBlockNum)
}

blockStateHex, err := hex.DecodeString(chunks[4])
if err != nil {
return nil, fmt.Errorf("unable to decode block %d state hex: %w", blockNum, err)
}

if err := ctx.hydrator.HydrateBlock(ctx.block, blockStateHex); err != nil {
return nil, fmt.Errorf("hydrate block %d: %w", blockNum, err)
}

block := ctx.block

zlog.Debug("blocking until abi decoder has decoded every transaction pushed to it")
err = ctx.abiDecoder.endBlock(ctx.block)
if err != nil {
return nil, fmt.Errorf("abi decoding post-process failed: %w", err)
}

zlog.Debug("abi decoder terminated all decoding operations, resetting block")
ctx.resetBlock()
return block, nil
}

// Line format:
//
// APPLIED_TRANSACTION ${block_num} ${trace_hex}
Expand Down

0 comments on commit 4492aca

Please sign in to comment.