Skip to content

Commit

Permalink
bump firehose-core, fix info endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
sduchesneau committed Aug 23, 2024
1 parent 3050401 commit 2898af8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 91 deletions.
99 changes: 17 additions & 82 deletions cmd/fireeth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/streamingfast/cli"
firecore "github.com/streamingfast/firehose-core"
fhCmd "github.com/streamingfast/firehose-core/cmd"
"github.com/streamingfast/firehose-core/firehose/info"
"github.com/streamingfast/firehose-ethereum/codec"
ethss "github.com/streamingfast/firehose-ethereum/substreams"
"github.com/streamingfast/firehose-ethereum/transform"
Expand Down Expand Up @@ -140,115 +141,49 @@ func Chain() *firecore.Chain[*pbeth.Block] {
var version = "dev"

var fillChainInfoResponse = func(block *pbbstream.Block, resp *pbfirehose.InfoResponse) error {
resp.FirstStreamableBlockId = block.Id
resp.BlockIdEncoding = pbfirehose.InfoResponse_BLOCK_ID_ENCODING_HEX

ethBlock := &pbeth.Block{}
if err := block.Payload.UnmarshalTo(ethBlock); err != nil {
return fmt.Errorf("cannot decode first streamable block: %w", err)
}

var detailLevel string
var detailLevelFromBlock string
switch ethBlock.DetailLevel {
case pbeth.Block_DETAILLEVEL_BASE:
detailLevel = "base"
detailLevelFromBlock = "base"
case pbeth.Block_DETAILLEVEL_EXTENDED:
detailLevel = "extended"
detailLevelFromBlock = "extended"
default:
return fmt.Errorf("unknown detail level in block: %q", ethBlock.DetailLevel)
}

var flagDetailLevel string
var detailLevelFromConfig string
for _, feature := range resp.BlockFeatures {
if feature == "base" || feature == "extended" || feature == "hybrid" {
flagDetailLevel = feature
detailLevelFromConfig = feature
break
}
}
switch flagDetailLevel {

switch detailLevelFromConfig {
case "":
resp.BlockFeatures = append(resp.BlockFeatures, detailLevel)
resp.BlockFeatures = append(resp.BlockFeatures, detailLevelFromBlock)
case "hybrid":
// we ignore the detail level from blocks in this case
default:
if flagDetailLevel != detailLevel {
return fmt.Errorf("detail level defined in flag: %q inconsistent with the one seen in blocks %q", flagDetailLevel, detailLevel)
if detailLevelFromConfig != detailLevelFromBlock {
return fmt.Errorf("detail level defined in flag: %q inconsistent with the one seen in blocks %q", detailLevelFromConfig, detailLevelFromBlock)
}
}

if resp.ChainName != "" {
if chain := knownChains.byName(resp.ChainName); chain != nil {
if block.Number == chain.genesisBlockNumber && chain.genesisBlockID != block.Id { // we can only check if first-streamable-block == gensis block
return fmt.Errorf("chain name defined in flag: %q inconsistent with the genesis block ID %q (expected: %q)", resp.ChainName, ox(block.Id), ox(chain.genesisBlockID))
}
resp.ChainName = chain.name
resp.ChainNameAliases = chain.aliases
} else if chain := knownChains.byBlock(block.Number, block.Id); chain != nil {
return fmt.Errorf("chain name defined in flag: %q inconsistent with the one discovered from genesis block %q", resp.ChainName, chain.name)
}
} else {
if chain := knownChains.byBlock(block.Number, block.Id); chain != nil {
resp.ChainName = chain.name
resp.ChainNameAliases = chain.aliases
}
// The firecore default filler will fill the encoding, genesisBlock ID/number and the chain name/aliases if it can
// It requires the BlockFeatures to be filled with the detail level
if err := info.DefaultInfoResponseFiller(block, resp); err != nil {
return err
}

return nil
}

func ox(in string) string {
return "0x" + in
}

type knownChain struct {
name string
aliases []string
genesisBlockID string
genesisBlockNumber uint64
}

type chainList []*knownChain

func (c chainList) byBlock(blockNum uint64, blockID string) *knownChain {
for _, chain := range knownChains {
if chain.genesisBlockNumber == blockNum && chain.genesisBlockID == blockID {
return chain
}
if resp.ChainName == "arbitrum-one" && detailLevelFromConfig == "" && resp.FirstStreamableBlockNum < 22_207_817 {
return fmt.Errorf("chain arbitrum-one specifically requires a block detail level to be set under 'block features', since the first 22_207_817 blocks are always type 'base', (set it to 'hybrid')")
}
return nil
}

func (c chainList) byName(name string) *knownChain {
for _, chain := range knownChains {
if chain.name == name {
return chain
}
for _, alias := range chain.aliases {
if alias == name {
return chain
}
}
}
return nil
}

var knownChains = chainList{
{
name: "mainnet",
aliases: []string{"ethereum"},
genesisBlockID: "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
genesisBlockNumber: 0,
},
{
name: "matic",
aliases: []string{"polygon"},
genesisBlockID: "a9c28ce2141b56c474f1dc504bee9b01eb1bd7d1a507580d5519d4437a97de1b",
genesisBlockNumber: 0,
},
{
name: "bsc",
aliases: []string{"bnb"},
genesisBlockID: "0d21840abff46b96c84b2ac9e10e4f5cdaeb5693cb665db62a2f3b02d2d57b5b",
genesisBlockNumber: 0,
},
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ require (
github.com/streamingfast/dstore v0.1.1-0.20240419152712-b7df14cba7b5
github.com/streamingfast/eth-go v0.0.0-20240312122859-216e183c0b7f
github.com/streamingfast/firehose v0.1.1-0.20240118135215-dcf04d40bfcd
github.com/streamingfast/firehose-core v1.5.8-0.20240821202218-51b2c612ed28
github.com/streamingfast/firehose-core v1.5.8-0.20240823191330-7cebed07a97e
github.com/streamingfast/firehose-ethereum/types v0.0.0-20240603154554-acc011d4f8c4
github.com/streamingfast/jsonpb v0.0.0-20210811021341-3670f0aa02d0
github.com/streamingfast/logging v0.0.0-20230608130331-f22c91403091
github.com/streamingfast/pbgo v0.0.6-0.20240821201153-468db4096ff0
github.com/streamingfast/pbgo v0.0.6-0.20240823134334-812f6a16c5cb
github.com/streamingfast/shutter v1.5.0
github.com/streamingfast/substreams v1.9.4-0.20240820153702-37a109caa0da
github.com/streamingfast/substreams v1.9.4-0.20240823175139-fee92bc72fad
github.com/stretchr/testify v1.9.0
github.com/test-go/testify v1.1.4
github.com/tidwall/gjson v1.14.1
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,8 @@ github.com/streamingfast/eth-go v0.0.0-20240312122859-216e183c0b7f h1:1LwsmRVENf
github.com/streamingfast/eth-go v0.0.0-20240312122859-216e183c0b7f/go.mod h1:UEm8dqibr3c3A1iIA3CHpkhN7j3X78prN7/55sXf3A0=
github.com/streamingfast/firehose v0.1.1-0.20240118135215-dcf04d40bfcd h1:t5n8dDcgUi7t36Qwxm19K4H2vyOLJfY6MHxTbOvK1z8=
github.com/streamingfast/firehose v0.1.1-0.20240118135215-dcf04d40bfcd/go.mod h1:du6tys2Q6X2pRQ3JbCziWiy7Y7KrOcl4CSb9uiGsVxA=
github.com/streamingfast/firehose-core v1.5.8-0.20240821202218-51b2c612ed28 h1:5bI8Fw1ZZSTl3L8JUpb+Gl6f7L3IZoHM1/dBWnRNu7M=
github.com/streamingfast/firehose-core v1.5.8-0.20240821202218-51b2c612ed28/go.mod h1:nLuPRoD7tnKG9iCJdW6sXeDXmgisxQ79NEXxEcA7BvA=
github.com/streamingfast/firehose-core v1.5.8-0.20240823191330-7cebed07a97e h1:zZI40CTP/z4+CCrsHEyAI0rKdfd40WVaJL2+ddAdoCY=
github.com/streamingfast/firehose-core v1.5.8-0.20240823191330-7cebed07a97e/go.mod h1:DhQKs66VtGKhSQIvTELpT46ue4UElDFY91CQPsfFzL8=
github.com/streamingfast/firehose-ethereum/types v0.0.0-20240603154554-acc011d4f8c4 h1:gr6ew/RxqQNDtDejLsNE3oAkvyitrtlj15alAjRDKs8=
github.com/streamingfast/firehose-ethereum/types v0.0.0-20240603154554-acc011d4f8c4/go.mod h1:CG22ObinxSbKIP19bAj0uro0a290kzZTiBbjL8VR0SE=
github.com/streamingfast/jsonpb v0.0.0-20210811021341-3670f0aa02d0 h1:g8eEYbFSykyzIyuxNMmHEUGGUvJE0ivmqZagLDK42gw=
Expand All @@ -590,8 +590,8 @@ github.com/streamingfast/overseer v0.2.1-0.20210326144022-ee491780e3ef h1:9IVFHR
github.com/streamingfast/overseer v0.2.1-0.20210326144022-ee491780e3ef/go.mod h1:cq8CvbZ3ioFmGrHokSAJalS0lC+pVXLKhITScItUGXY=
github.com/streamingfast/payment-gateway v0.0.0-20240426151444-581e930c76e2 h1:bliib3pAObbM+6cKYQFa8axbCY/x6RczQZrOxdM7OZA=
github.com/streamingfast/payment-gateway v0.0.0-20240426151444-581e930c76e2/go.mod h1:DsnLrpKZ3DIDL6FmYVuxbC44fXvQdY7aCdSLMpbqZ8Q=
github.com/streamingfast/pbgo v0.0.6-0.20240821201153-468db4096ff0 h1:kfzU2GvvWt+RQtrHvfqv7zdRA4xv/3AusccIGG3+roM=
github.com/streamingfast/pbgo v0.0.6-0.20240821201153-468db4096ff0/go.mod h1:eDQjKBYg9BWE2BTaV3UZeLZ5xw05+ywA9RCFTmM1w5Y=
github.com/streamingfast/pbgo v0.0.6-0.20240823134334-812f6a16c5cb h1:Xqt4ned9ELmQMKcg7cFbm56MKG2gBjnE1M+2HObOs6w=
github.com/streamingfast/pbgo v0.0.6-0.20240823134334-812f6a16c5cb/go.mod h1:eDQjKBYg9BWE2BTaV3UZeLZ5xw05+ywA9RCFTmM1w5Y=
github.com/streamingfast/protoreflect v0.0.0-20231205191344-4b629d20ce8d h1:33VIARqUqBUKXJcuQoOS1rVSms54tgxhhNCmrLptpLg=
github.com/streamingfast/protoreflect v0.0.0-20231205191344-4b629d20ce8d/go.mod h1:aBJivEdekmFWYSQ29EE/fN9IanJWJXbtjy3ky0XD/jE=
github.com/streamingfast/sf-tracing v0.0.0-20240430173521-888827872b90 h1:94HllkX4ttYVilo8ZJv05b5z8JiMmqBvv4+Jdgk/+2A=
Expand All @@ -600,8 +600,8 @@ github.com/streamingfast/shutter v1.5.0 h1:NpzDYzj0HVpSiDJVO/FFSL6QIK/YKOxY0gJAt
github.com/streamingfast/shutter v1.5.0/go.mod h1:B/T6efqdeMGbGwjzPS1ToXzYZI4kDzI5/u4I+7qbjY8=
github.com/streamingfast/snapshotter v0.0.0-20230316190750-5bcadfde44d0 h1:Y15G1Z4fpEdm2b+/70owI7TLuXadlqBtGM7rk4Hxrzk=
github.com/streamingfast/snapshotter v0.0.0-20230316190750-5bcadfde44d0/go.mod h1:/Rnz2TJvaShjUct0scZ9kKV2Jr9/+KBAoWy4UMYxgv4=
github.com/streamingfast/substreams v1.9.4-0.20240820153702-37a109caa0da h1:dk5AfvQY3aJdW6CRzsDG3gDkY6ON/70RCv2iB9P8FSI=
github.com/streamingfast/substreams v1.9.4-0.20240820153702-37a109caa0da/go.mod h1:Q/h8Mxe+MKVZqU9wIpMxLKZHb0hLIACZvDiBnR+IVyI=
github.com/streamingfast/substreams v1.9.4-0.20240823175139-fee92bc72fad h1:Js7hQE7ZwhLaBgy8Hd9/mZDLiqdgY/QbMwlAXBfSf9w=
github.com/streamingfast/substreams v1.9.4-0.20240823175139-fee92bc72fad/go.mod h1:GchLx+0trEb9E9QvPBbWwY2rVsJkpcw66ibpLn0OtVE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
Expand Down

0 comments on commit 2898af8

Please sign in to comment.