Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BLOCK-2572] add read for new block log #52

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading