Skip to content

Commit

Permalink
clip func
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-bousfield committed Apr 27, 2022
1 parent 25bdd8c commit 22148c3
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions arbitrum/apibackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,7 @@ func (a *APIBackend) FeeHistory(
}

nitroGenesis := core.NitroGenesisBlock
latestBlock := rpc.BlockNumber(a.CurrentBlock().NumberU64())
if newestBlock == rpc.LatestBlockNumber || newestBlock == rpc.PendingBlockNumber {
newestBlock = latestBlock
}
if newestBlock > latestBlock {
newestBlock = latestBlock
}
if newestBlock < nitroGenesis {
newestBlock = nitroGenesis
}
newestBlock, latestBlock := ClipToPostNitroGenesis(a, newestBlock)

maxFeeHistory := int(a.b.config.FeeHistoryMaxBlockCount)
if blocks > maxFeeHistory {
Expand Down Expand Up @@ -425,3 +416,21 @@ func (a *APIBackend) ChainConfig() *params.ChainConfig {
func (a *APIBackend) Engine() consensus.Engine {
return a.blockChain().Engine()
}

type GetsCurrentBlock interface {
CurrentBlock() *types.Block
}

func ClipToPostNitroGenesis(getter GetsCurrentBlock, blockNum rpc.BlockNumber) (rpc.BlockNumber, rpc.BlockNumber) {
currentBlock := rpc.BlockNumber(getter.CurrentBlock().NumberU64())
if blockNum == rpc.LatestBlockNumber || blockNum == rpc.PendingBlockNumber {
blockNum = currentBlock
}
if blockNum > currentBlock {
blockNum = currentBlock
}
if blockNum < core.NitroGenesisBlock {
blockNum = core.NitroGenesisBlock
}
return blockNum, currentBlock
}

0 comments on commit 22148c3

Please sign in to comment.