Skip to content
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

Add async gas locking to built-in functions #2233

Merged
merged 20 commits into from
Aug 27, 2020

Conversation

camilbancioiu
Copy link
Contributor

@camilbancioiu camilbancioiu commented Aug 24, 2020

Lock a specified amount of gas before executing a built-in function, in case the call is asynchronous. The locked gas will be restored after execution, or in case of error. The intention is to keep some gas aside, in order to have a minimum amount left for the async callback.

Extra additions to integrationTests/vm/arwen/utils.go, to allow easy extraction of info directly from SmartContractResults (TODO: add the same functionality to TestProcessorNode).

@sasurobert sasurobert changed the base branch from master to development August 24, 2020 09:50
process/smartContract/process.go Outdated Show resolved Hide resolved
process/smartContract/process.go Outdated Show resolved Hide resolved
sasurobert
sasurobert previously approved these changes Aug 24, 2020
}

sc.penalizeUserIfNeeded(tx, txHash, vmInput.CallType, vmInput.GasProvided, vmOutput)

// Restore gas set aside for the async callback, if any; this amount will
// still be available to the async callback, even after being penalized for providing too much gas
vmOutput.GasRemaining += lockedGas
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Penalization is done in penalizeUserIfNeeded method only if: callType != vmcommon.AsynchronousCall

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the comment.

@camilbancioiu camilbancioiu marked this pull request as ready for review August 26, 2020 10:36
@@ -1004,6 +1008,12 @@ func (tpn *TestProcessorNode) initInnerProcessors() {
}
builtInFuncs, _ := builtInFunctions.CreateBuiltInFunctionContainer(argsBuiltIn)

if len(TestBuiltinFunctions) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "if" is not really necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@@ -250,7 +250,7 @@ func (sc *scProcessor) doExecuteSmartContractTransaction(
snapshot := sc.accounts.JournalLen()

var vmInput *vmcommon.ContractCallInput
vmInput, err = sc.createVMCallInput(tx)
vmInput, err = sc.createVMCallInput(tx, txHash)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the original txhash which should be needed in case of async callback.use setOriginalTxHash function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. Replicated the behavior of setOriginalTxHash() in sc.createVMCallInput().

@@ -71,6 +71,7 @@ func (sc *scProcessor) createVMCallInput(tx data.TransactionHandler) (*vmcommon.
vmCallInput.CallType = callType
vmCallInput.RecipientAddr = tx.GetRcvAddr()
vmCallInput.Function = function
vmCallInput.OriginalTxHash = txHash

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please set originaltxhash and currentxhash as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

sasurobert
sasurobert previously approved these changes Aug 27, 2020
sasurobert
sasurobert previously approved these changes Aug 27, 2020
Copy link
Contributor

@LucianMincu LucianMincu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System tests passed.

@LucianMincu LucianMincu merged commit 27907cb into development Aug 27, 2020
@LucianMincu LucianMincu deleted the fix-callback-gas-builtin branch August 27, 2020 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants