wip: adding some implementation of the finalizer, defining needed int…#1481
wip: adding some implementation of the finalizer, defining needed int…#1481Psykepro merged 11 commits intofeature/newSequencerfrom
Conversation
…erfaces by the finalizer from the dbmanager, and implementing the remaining resourses Sub. Signed-off-by: Nikolay Nedkov <nikolai_nedkov@yahoo.com>
arnaubennassar
left a comment
There was a problem hiding this comment.
- Sorry for too many comments saying
You can do this in a later PR as here the priority is to define interfaces ASAP. It was to help identifying what needs to be done now and what can be done later... Was lazy so just copy pasted it 🙃 - Also not to be done now, but in some parts of the code there already too many identation levels (at least I've counted 5...). As a rule of thumb when this happens it's time to start thinking about splitting into multiple functions
sequencer/worker.go
Outdated
| r.remainingBytes -= other.remainingBytes | ||
| r.remainingGas -= other.remainingGas |
There was a problem hiding this comment.
This also needs underflow check
There was a problem hiding this comment.
It has it in line 112 this check everything. It is first checking every field for underflow before doing any changes.
sequencer/worker.go
Outdated
| return nil | ||
| } | ||
|
|
||
| func (r *RemainingResources) checkForResourcesOverflow(other RemainingResources) error { |
There was a problem hiding this comment.
| func (r *RemainingResources) checkForResourcesOverflow(other RemainingResources) error { | |
| func (r *RemainingResources) checkForResourcesUnderflow(other RemainingResources) error { |
There was a problem hiding this comment.
Ops, yep mistake here.
pool/transaction.go
Outdated
| } | ||
|
|
||
| // SubZkCounters subtract zk counters with passed zk counters (not safe) | ||
| func (zkc *ZkCounters) SubZkCounters(txZkCounters ZkCounters) { |
There was a problem hiding this comment.
I'm not very happy about this (because for how it used to be, not your changes). Things that IMO could imporve current situation:
- Move the struct to
statepackage - Ideally reuse the counters from the proto interface so we don't need to reparse (maybe by wrapping)
ZkCounters=>ZKCounters🙏- Include the underflow logic already in the
SubZkCountersmethod SubZkCounters=>Sub
There was a problem hiding this comment.
The only actual request here is the renamings of the functions, otherwise it's just suggestions up to you to implement if you consider them legit
sequencer/finalizer.go
Outdated
| GER: lastBatch.GlobalExitRoot, | ||
| initialStateRoot: lastBatch.StateRoot, | ||
| intermediaryStateRoot: lastBatch.StateRoot, | ||
| txs: make([]TxTracker, 0, f.maxTxsPerBatch), |
There was a problem hiding this comment.
Exisitng transactions in the batch should be also loaded from DB. You can do this in a later PR as here the priority is to define interfaces ASAP
There was a problem hiding this comment.
This I had in mind just wanted to make quick PR for the interfaces.
sequencer/finalizer.go
Outdated
| wipBatch := wipBatch{} | ||
| wipBatch := wipBatch{ | ||
| GER: lastBatch.GlobalExitRoot, | ||
| initialStateRoot: lastBatch.StateRoot, |
There was a problem hiding this comment.
The initial state root is actually yhe state root stored in the previous batch (the last closed batch). You can do this in a later PR as here the priority is to define interfaces ASAP
There was a problem hiding this comment.
This I had in mind just wanted to make quick PR for the interfaces.
sequencer/finalizer.go
Outdated
| tx := f.worker.GetBestFittingTx(wipBatch.remainingResources) | ||
| if tx != nil { | ||
| lenOfTxs := len(wipBatch.txs) | ||
| isFirstTx := lenOfTxs == 1 |
There was a problem hiding this comment.
| isFirstTx := lenOfTxs == 1 | |
| isFirstTx := lenOfTxs == 0 |
At this point, tx is not added yet into wipBatch.txs. If wipBatch.txs == 1 it means that in previous iterations there has been a tx added into the batch, and that tx was actually the first one.
Beyond that we may consider to execute a batch with no txs at all to produce the GER update, and here use always empty hash. We can talk about this later. You can do this in a later PR as here the priority is to define interfaces ASAP
There was a problem hiding this comment.
Ops, yep mistake here.. from hurrying :D
sequencer/finalizer.go
Outdated
| from, err := types.Sender(types.NewEIP155Signer(processedTx.Tx.ChainId()), &processedTx.Tx) | ||
| if err != nil { | ||
| from, err = types.Sender(types.HomesteadSigner{}, &processedTx.Tx) | ||
| } |
There was a problem hiding this comment.
We should be able to get the from from the TxTracker. You can do this in a later PR as here the priority is to define interfaces ASAP
There was a problem hiding this comment.
So this I guess to be provided by the DbManager to the struct form the database?
sequencer/finalizer.go
Outdated
| processBatchRequest.OldAccInputHash = result.NewAccInputHash | ||
| // We store the processed transaction, add it to the batch and delete from the pool atomically. | ||
| go f.dbManager.StoreProcessedTxAndDeleteFromPool(ctx, wipBatch.batchNumber, processedTx) | ||
| go f.worker.UpdateAfterSingleSuccessfulTxExecution(from, result.TouchedAddresses) |
There was a problem hiding this comment.
| go f.worker.UpdateAfterSingleSuccessfulTxExecution(from, result.TouchedAddresses) | |
| f.worker.UpdateAfterSingleSuccessfulTxExecution(from, result.TouchedAddresses) |
We decided to do this synchronously. The idea is to compromise a bit of performance but to gain more security (improve "hit ratio")
There was a problem hiding this comment.
Yep, sorry mistake here.
sequencer/finalizer.go
Outdated
| AccInputHash: processBatchRequest.OldAccInputHash, | ||
| StateRoot: wipBatch.intermediaryStateRoot, | ||
| LocalExitRoot: processBatchRequest.GlobalExitRoot, | ||
| Txs: ethTxs, |
There was a problem hiding this comment.
I would like to review this to see if we can directly pass wipBatch.txs here. Also it would be nice if we can stop working with types.Transaction in the first place and use the TxTracker for the sequencer and "raw txs" (just the encoded tx as []byte) in the state.
I'm not sure about how feasible is this, but at least is worth exploring
There was a problem hiding this comment.
Okay, will check if possible to use everywhere the raw tx.
state/types.go
Outdated
| TxData []byte | ||
| SequencerAddress common.Address | ||
| Timestamp uint64 | ||
| IsFirstTx bool |
There was a problem hiding this comment.
I think this is not needed here. This should be used for the GER empty hack, but we're already taking into consideration this in the finalizer.
With that being said, since this is something related to how the executor works, it will make a lot of sense to take care bout this using the isFirstTx, but then we don't need to do it in the finalizer. Also if it's the state who needs to do that, then it also needs to know if the inteeractions is meant to be done in the tx by tx mode or in the full batch mode...
Up to you, essentially you have to either:
- Remove
IsFirstTxfrom the struct - Remoe the GER = empty hash from finalizer, and add a
tx by txflag in the process request struct
| @@ -43,11 +47,17 @@ type txManager interface { | |||
|
|
|||
| type workerInterface interface { | |||
There was a problem hiding this comment.
We need to add also "func (w *Worker) AddTx(tx TxTracker)" function that is used by the Pool Loader to load txs from the Pool to the Worker
There was a problem hiding this comment.
This PR is just for the interfaces needed in the dbManager by the Finalizer. But after I get back from the vacation, because you will be still on vacation I can take a look at adding some of the needed in the Worker no probs! :))
37c0052 to
a2ecd09
Compare
a2ecd09 to
ada278d
Compare
sequencer/interfaces.go
Outdated
| } | ||
|
|
||
| // The dbManager will need to handle the errors inside the functions which don't return error as they will be used async in the other abstractions. | ||
| // Also if dbTx is missing this needs also to be handled ion the dbManager |
There was a problem hiding this comment.
| // Also if dbTx is missing this needs also to be handled ion the dbManager | |
| // Also if dbTx is missing this needs also to be handled in the dbManager |
Signed-off-by: Nikolay Nedkov <nikolai_nedkov@yahoo.com>
969fa8a to
86a7241
Compare
Signed-off-by: Nikolay Nedkov <nikolai_nedkov@yahoo.com>
86a7241 to
bfa53aa
Compare
Signed-off-by: Nikolay Nedkov <nikolai_nedkov@yahoo.com>
5cab1b3 to
b3c3ccf
Compare
* WIP * WIP * WIP
…ng small refactor. Signed-off-by: Nikolay Nedkov <nikolai_nedkov@yahoo.com>
975f1d5 to
ec6ee2e
Compare
Signed-off-by: Nikolay Nedkov <nikolai_nedkov@yahoo.com>
Signed-off-by: Nikolay Nedkov <nikolai_nedkov@yahoo.com>
Signed-off-by: Nikolay Nedkov <nikolai_nedkov@yahoo.com>
…erfaces by the finalizer from the dbmanager, and implementing the remaining resourses Sub.
Signed-off-by: Nikolay Nedkov nikolai_nedkov@yahoo.com
Related to issue #1478.
What does this PR do?
Adding some of the implementations (still WIP). Mostly to define needed interfaces by the dbManager to unblock @ToniRamirezM. I've added to the proto the TouchedAddresses and generated the proto files.
I got carried away and implemented the
remainingResources.Submethod but I think the implementation is very clean. :)Reviewers
Main reviewers: