-
Notifications
You must be signed in to change notification settings - Fork 198
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
EN-7307: transaction execution simulator #2218
Conversation
api/transaction/routes.go
Outdated
} | ||
|
||
executionResults.Hash = hex.EncodeToString(txHash) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete empty line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cmd/node/factory/structs.go
Outdated
@@ -2,6 +2,7 @@ package factory | |||
|
|||
import ( | |||
"errors" | |||
"github.com/ElrondNetwork/elrond-go/epochStart/bootstrap/disabled" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goimports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cmd/node/factory/structs.go
Outdated
@@ -1323,6 +1332,13 @@ func newShardBlockProcessor( | |||
return nil, errors.New("could not create transaction statisticsProcessor: " + err.Error()) | |||
} | |||
|
|||
txSimulatorProcessorArgs := argsNewTxProcessor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do the same for the underlying smart contract processor - you need to feed diabled fee handler and new intermediate processor for the simulator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cmd/node/factory/structs.go
Outdated
@@ -1323,6 +1332,13 @@ func newShardBlockProcessor( | |||
return nil, errors.New("could not create transaction statisticsProcessor: " + err.Error()) | |||
} | |||
|
|||
txSimulatorProcessorArgs := argsNewTxProcessor | |||
txSimulatorProcessorArgs.Accounts = disabled.NewAccountsAdapter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of disabled accounts adapter - you have to create a read only accounts adapter. thus you need a new component which gets the accountsDB as parameter and does all the reading from it, and in case of writes it writes into a cache, or it has an empty implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
node/txsimulator/txSimulator.go
Outdated
|
||
// ProcessTx will process the transaction in a special environment, where state-writing is not allowed | ||
func (ts *transactionSimulator) ProcessTx(accounts state.AccountsAdapter, tx *transaction.Transaction) (*transaction.SimulationResults, error) { | ||
newAccounts, err := NewReadOnlyAccountsDB(accounts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can create this only once - at constructor level. and you have access to all the current state. no need to recreate for every simulation process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
// JournalLen will call the original accounts' function with the same name | ||
func (w *readOnlyAccountsDB) JournalLen() int { | ||
w.mutAccounts.RLock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for mutex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
# Conflicts: # api/mock/facade.go # cmd/node/factory/structs.go # cmd/node/main.go
facade/nodeFacade_test.go
Outdated
) | ||
|
||
//TODO increase code coverage | ||
|
||
type interf interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete this :) no need for that and for the next 20 lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pushed by mistake. removed
node/txsimulator/txSimulator.go
Outdated
} | ||
|
||
// New returns a new instance of a transactionSimulator | ||
func New(txProcessor TransactionProcessor, accountsAdapter state.AccountsAdapter) (*transactionSimulator, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New what ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the package is called txsimulator
so the constructor's call will result in txsimulator.New()
. txsimulator.NewTxSimulator()
would have been redundant
process/transaction/metaProcess.go
Outdated
@@ -20,6 +21,16 @@ type metaTxProcessor struct { | |||
txTypeHandler process.TxTypeHandler | |||
} | |||
|
|||
// GetSmartContractResults returns the smart contract results | |||
func (txProc *metaTxProcessor) GetSmartContractResults() map[string]data.TransactionHandler { | |||
return make(map[string]data.TransactionHandler) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meta sc processor creates smart contract results as well. you do not these. As in txSimulator you could have the scrForwarder and receiptForwarders and take those data from there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. refactored and created structs for a more friendly API result
process/transaction/metaProcess.go
Outdated
} | ||
|
||
// SetAccountsAdapter updates the accounts adapter | ||
func (txProc *metaTxProcessor) SetAccountsAdapter(accounts state.AccountsAdapter) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for this set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch. this resulted in overwriting the read-only accounts db into the real one
process/transaction/shardProcess.go
Outdated
|
||
// GetSmartContractResults returns the smart contract results in the current round | ||
func (txProc *txProcessor) GetSmartContractResults() map[string]data.TransactionHandler { | ||
return txProc.scrForwarder.GetAllCurrentFinishedTxs() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
process/transaction/shardProcess.go
Outdated
// SetAccountsAdapter will update the accounts adapter if the provided one is not nil | ||
func (txProc *txProcessor) SetAccountsAdapter(accounts state.AccountsAdapter) { | ||
if !check.IfNil(accounts) { | ||
txProc.accounts = accounts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for this set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
cmd/node/main.go
Outdated
) | ||
processComponents, err := factory.ProcessComponentsFactory(processArgs) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
transactionSimulator, err := txsimulator.New(*txSimulatorProcessorArgs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New what ? make a better naming for the constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. renamed
node/txsimulator/txSimulator.go
Outdated
if err != nil { | ||
return err | ||
} | ||
receiptsForwarder, err := ts.intermProcContainer.Get(block.ReceiptBlock) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no receipt block in case of metachain - thus this will fail.
What you should do it iterate all processors and call createblockstarted. Receipts are created only in intra shard move balance transfers with too much gas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. in case of meta, apply only the smart contract results and in case of shard, also the receipts. and on defer now it closes all the processors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on AZ-WEU with proxy EN-7303-tx-simulation
Upgrade path master -> EN-7307-tx-execution-simulator tested on AZ-UKS
5ab702d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
System tests passed.
Transaction execution simulator. It will work via the API endpoint
/transaction/simulate
which receives the same request as the/transaction/send
.Created a new component that will simulate the execution of a transaction without affecting the state of the blockchain. In order to achieve this, some components of the new
transaction processor
were disabled or changed to read-only.Testing steps:
api.toml
file)/transaction/simulate
endpoint. Multiple scenarios are expected: