Skip to content

Commit

Permalink
feat: allow triggering one-off CCC on a block (#1043)
Browse files Browse the repository at this point in the history
Co-authored-by: Péter Garamvölgyi <[email protected]>
  • Loading branch information
omerfirmak and Thegaram authored Sep 17, 2024
1 parent 1d02d04 commit 89639dd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
21 changes: 21 additions & 0 deletions eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/scroll-tech/go-ethereum/internal/ethapi"
"github.com/scroll-tech/go-ethereum/log"
"github.com/scroll-tech/go-ethereum/rlp"
"github.com/scroll-tech/go-ethereum/rollup/ccc"
"github.com/scroll-tech/go-ethereum/rpc"
"github.com/scroll-tech/go-ethereum/trie"
)
Expand Down Expand Up @@ -812,3 +813,23 @@ func (api *ScrollAPI) GetSkippedTransactionHashes(ctx context.Context, from uint

return hashes, nil
}

// CalculateRowConsumptionByBlockNumber
func (api *ScrollAPI) CalculateRowConsumptionByBlockNumber(ctx context.Context, number rpc.BlockNumber) (*types.RowConsumption, error) {
block := api.eth.blockchain.GetBlockByNumber(uint64(number.Int64()))
if block == nil {
return nil, errors.New("block not found")
}

// todo: fix temp AsyncChecker leaking the internal Checker instances
var checkErr error
asyncChecker := ccc.NewAsyncChecker(api.eth.blockchain, 1, false).WithOnFailingBlock(func(b *types.Block, err error) {
log.Error("failed to calculate row consumption on demand", "number", number, "hash", b.Hash().Hex(), "err", err)
checkErr = err
})
if err := asyncChecker.Check(block); err != nil {
return nil, err
}
asyncChecker.Wait()
return rawdb.ReadBlockRowConsumption(api.eth.ChainDb(), block.Hash()), checkErr
}
6 changes: 6 additions & 0 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,12 @@ web3._extend({
inputFormatter: [web3._extend.formatters.inputCallFormatter, web3._extend.formatters.inputBlockNumberFormatter],
outputFormatter: web3._extend.utils.toDecimal
}),
new web3._extend.Method({
name: 'calculateRowConsumptionByBlockNumber',
call: 'scroll_calculateRowConsumptionByBlockNumber',
params: 1,
inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter]
}),
],
properties:
[
Expand Down

0 comments on commit 89639dd

Please sign in to comment.