-
Notifications
You must be signed in to change notification settings - Fork 285
feat: pipelined state processor for follower nodes #894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b1491c4
4f2963a
4a138ce
e0b317b
e5011a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package stateprocessor | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "time" | ||
|
|
||
| "github.com/scroll-tech/go-ethereum/core" | ||
| "github.com/scroll-tech/go-ethereum/core/rawdb" | ||
| "github.com/scroll-tech/go-ethereum/core/state" | ||
| "github.com/scroll-tech/go-ethereum/core/types" | ||
| "github.com/scroll-tech/go-ethereum/core/vm" | ||
| "github.com/scroll-tech/go-ethereum/rollup/circuitcapacitychecker" | ||
| "github.com/scroll-tech/go-ethereum/rollup/pipeline" | ||
| ) | ||
|
|
||
| var _ core.Processor = (*Processor)(nil) | ||
|
|
||
| type Processor struct { | ||
| chain *core.BlockChain | ||
| ccc *circuitcapacitychecker.CircuitCapacityChecker | ||
| } | ||
|
|
||
| func NewProcessor(bc *core.BlockChain) *Processor { | ||
| return &Processor{ | ||
| chain: bc, | ||
| ccc: circuitcapacitychecker.NewCircuitCapacityChecker(true), | ||
| } | ||
| } | ||
|
|
||
| func (p *Processor) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, []*types.Log, uint64, error) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original plan was to move CCC out of the block processing loop, so that it's not blocking it. By moving CCC from I feel like:
|
||
| if block.Transactions().Len() == 0 { | ||
| return types.Receipts{}, []*types.Log{}, 0, nil | ||
| } | ||
|
|
||
| header := block.Header() | ||
| header.GasUsed = 0 | ||
|
|
||
| nextL1MsgIndex := uint64(0) | ||
| // assume L1 message indexes were validated by block validator | ||
| if block.Transactions().Len() > 0 { | ||
| if l1Msg := block.Transactions()[0].AsL1MessageTx(); l1Msg != nil { | ||
| nextL1MsgIndex = l1Msg.QueueIndex | ||
| } | ||
| } | ||
|
|
||
| pl := pipeline.NewPipeline(p.chain, cfg, statedb, header, nextL1MsgIndex, p.ccc).WithReplayMode() | ||
| pl.Start(time.Now().Add(time.Minute)) | ||
| defer pl.Release() | ||
|
|
||
| for _, tx := range block.Transactions() { | ||
| res, err := pl.TryPushTxn(tx) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Originally, we'd trace and ccc the whole block in one step (different ccc API). By using a pipeline, we now process tx-by-tx in a pipelined manner. Are the CCC results the same? And do we gain a lot from this? |
||
| if err != nil && !errors.Is(err, pipeline.ErrUnexpectedL1MessageIndex) { | ||
| return nil, nil, 0, err | ||
| } | ||
|
|
||
| if res != nil { | ||
| return nil, nil, 0, fmt.Errorf("pipeline ended prematurely %v", res.CCCErr) | ||
| } | ||
| } | ||
|
|
||
| pl.Stop() | ||
| res := <-pl.ResultCh | ||
| if res.CCCErr != nil { | ||
| return nil, nil, 0, res.CCCErr | ||
| } | ||
|
|
||
| rawdb.WriteBlockRowConsumption(p.chain.Database(), block.Hash(), res.Rows) | ||
| return res.FinalBlock.Receipts, res.FinalBlock.CoalescedLogs, res.FinalBlock.Header.GasUsed, nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.