Skip to content

Commit

Permalink
feat: add Firehose logs
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Dec 16, 2023
1 parent 3ebbfb0 commit 86bcfeb
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ func (b *Blockchain) Store(block *core.Block, blockCommitments *core.BlockCommit
if err := verifyBlock(txn, block); err != nil {
return err
}

// TODO: add runtime option to toggle this on and off
PrintFirehoseLogs(block)

if err := core.NewState(txn).Update(block.Number, stateUpdate, newClasses); err != nil {
return err
}
Expand Down Expand Up @@ -372,6 +376,46 @@ func (b *Blockchain) Store(block *core.Block, blockCommitments *core.BlockCommit
})
}

// Firehose integration
func PrintFirehoseLogs(block *core.Block) {
fmt.Printf("FIRE BLOCK_BEGIN %d\n", block.Number)
for indTx, tx := range block.Transactions {
fmt.Printf("FIRE BEGIN_TRX 0x%X ", tx.Hash().Bytes())
switch tx.(type) {
case *core.DeployTransaction:
fmt.Println("DEPLOY")
case *core.InvokeTransaction:
fmt.Println("INVOKE_FUNCTION")
case *core.DeclareTransaction:
fmt.Println("DECLARE")
case *core.DeployAccountTransaction:
fmt.Println("DEPLOY_ACCOUNT")
case *core.L1HandlerTransaction:
fmt.Println("L1_HANDLER")
default:
panic("not a transaction")
}
receipt := block.Receipts[indTx]
for indEvent, event := range receipt.Events {
fmt.Printf("FIRE TRX_BEGIN_EVENT 0x%X 0x%X\n", tx.Hash().Bytes(), event.From.Bytes())

for _, key := range event.Keys {
fmt.Printf("FIRE TRX_EVENT_KEY 0x%X %d 0x%X\n", tx.Hash().Bytes(), indEvent, key.Bytes())
}

for _, data := range event.Data {
fmt.Printf("FIRE TRX_EVENT_DATA 0x%X %d 0x%X\n", tx.Hash().Bytes(), indEvent, data.Bytes())
}
}
}
fmt.Printf("FIRE BLOCK_END %d 0x%X 0x%X %d %d\n",
block.Number,
block.Hash.Bytes(),
block.ParentHash.Bytes(),
block.Timestamp,
len(block.Transactions))
}

// VerifyBlock assumes the block has already been sanity-checked.
func (b *Blockchain) VerifyBlock(block *core.Block) error {
return b.database.View(func(txn db.Transaction) error {
Expand Down

0 comments on commit 86bcfeb

Please sign in to comment.