Skip to content

Commit

Permalink
Merge pull request #119 from openrelayxyz/feature/archive
Browse files Browse the repository at this point in the history
Feature/archive
  • Loading branch information
AusIV authored Apr 22, 2024
2 parents 30309d6 + db72be7 commit 97f2884
Show file tree
Hide file tree
Showing 17 changed files with 853 additions and 226 deletions.
27 changes: 24 additions & 3 deletions api/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql"

log "github.com/inconshreveable/log15"

"github.com/openrelayxyz/cardinal-evm/rlp"
"github.com/openrelayxyz/cardinal-rpc"
"github.com/openrelayxyz/cardinal-types"
Expand All @@ -19,6 +20,9 @@ import (
var (
hitMeter = metrics.NewMajorMeter("/flume/hit")
missMeter = metrics.NewMajorMeter("/flume/miss")

heavyBlockHashHit = metrics.NewMinorMeter("/flume/hbh/hit")
heavyBlockHashMiss = metrics.NewMinorMeter("/flume/hbh/miss")
)

type BlockAPI struct {
Expand All @@ -45,16 +49,17 @@ func (api *BlockAPI) ChainId(ctx context.Context) hexutil.Uint64 {
return hexutil.Uint64(api.cfg.Chainid)
}

func (api *BlockAPI) BlockNumber(ctx context.Context) (hexutil.Uint64, error) {
func (api *BlockAPI) BlockNumber(ctx context.Context) hexutil.Uint64 {

log.Debug("eth_blockNumber served from flume light by default")
hitMeter.Mark(1)

blockNo, err := getLatestBlock(ctx, api.db)
if err != nil {
return 0, err
log.Error("Error returned from getLatestBlock", "err", err)
return 0
}
return hexutil.Uint64(blockNo), nil
return hexutil.Uint64(blockNo)
}

var (
Expand Down Expand Up @@ -136,6 +141,10 @@ func (api *BlockAPI) GetBlockByHash(ctx context.Context, blockHash types.Hash, i
if err != nil {
return nil, err
}
if responseShell == nil {
heavyBlockHashMiss.Mark(1)
}
heavyBlockHashHit.Mark(1)
return responseShell, nil
}

Expand Down Expand Up @@ -234,6 +243,10 @@ func (api *BlockAPI) GetBlockTransactionCountByHash(ctx context.Context, blockHa
if err != nil {
return nil, err
}
if count == nil {
heavyBlockHashMiss.Mark(1)
}
heavyBlockHashHit.Mark(1)
return count, nil
}

Expand Down Expand Up @@ -321,6 +334,10 @@ func (api *BlockAPI) GetUncleCountByBlockHash(ctx context.Context, blockHash typ
if err != nil {
return nil, err
}
if count == nil {
heavyBlockHashMiss.Mark(1)
}
heavyBlockHashHit.Mark(1)
return count, nil
}

Expand Down Expand Up @@ -408,6 +425,10 @@ func (api *BlockAPI) GetBlockReceipts(ctx context.Context, input BlockNumberOrHa
if err != nil {
return nil, err
}
if rt == nil {
heavyBlockHashMiss.Mark(1)
}
heavyBlockHashHit.Mark(1)
return *rt, nil
}

Expand Down
5 changes: 1 addition & 4 deletions api/blockAPI_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,7 @@ func TestBlockNumber(t *testing.T) {
pl, _ := plugins.NewPluginLoader(cfg)
b := NewBlockAPI(db, 1, pl, cfg)
expectedResult, _ := hexutil.DecodeUint64("0x12ab5da")
test, err := b.BlockNumber(context.Background())
if err != nil {
t.Fatalf(err.Error())
}
test := b.BlockNumber(context.Background())
if test != hexutil.Uint64(expectedResult) {
t.Fatalf("BlockNumber() result not accurate")
}
Expand Down
Loading

0 comments on commit 97f2884

Please sign in to comment.