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

Sync calls #227

Merged
merged 54 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
3534f88
WIP: Code compiles after parametrizing modules and instances.
abizjak Dec 10, 2021
84d501e
WIP: Introduce handling of init V1 contracts.
abizjak Dec 12, 2021
19831e0
WIP: Introduce handling of inter-contract calls in the scheduler.
abizjak Dec 15, 2021
1c3e8dc
Allow deployment of V1 modules.
abizjak Dec 15, 2021
2c78a92
Implement serialization of V1 instances.
abizjak Dec 15, 2021
7079b80
Fix tests after changes to datatypes.
abizjak Dec 15, 2021
98111cb
Add V1 Wasm module version.
abizjak Dec 17, 2021
55ee729
Initial tests of V1 modules.
abizjak Dec 22, 2021
3ad4a23
More tests of contract invocations.
abizjak Dec 22, 2021
e5a0ec4
Add more checks to the call test.
abizjak Dec 22, 2021
c058152
Expose method to convert from return value to bytestring.
abizjak Dec 22, 2021
8a1e540
Add tests for transfers from a contract to an account in the synchron…
abizjak Dec 22, 2021
aac9385
Add V1 instances to globalstate tests.
abizjak Dec 23, 2021
6773577
Add tests for cross-version-contract calls.
abizjak Dec 23, 2021
cdd07b9
Make serialization of parameter size consistent, and revise tests acc…
abizjak Dec 23, 2021
e6c9ca1
Add documentation.
abizjak Dec 23, 2021
6e76821
Add P4 support for testing.
abizjak Dec 24, 2021
3e1917d
Remove needless use of lenses.
abizjak Dec 24, 2021
6dd1053
Haskell parts of invoking a contract as a query.
abizjak Dec 26, 2021
5b0e683
Expose invoke contract externally.
abizjak Dec 27, 2021
456babc
Use entrypoint names when specifying a call target for V1 contracts.
abizjak Jan 3, 2022
358ebee
Merge remote-tracking branch 'origin/main' into sync-calls
abizjak Jan 3, 2022
e802acb
Introduce an Interrupted event for transaction execution.
abizjak Jan 5, 2022
d69f485
Scope the calls.
abizjak Jan 6, 2022
8747175
Fix failure transfer through FFI.
abizjak Jan 6, 2022
eae7cec
Tell the invoker contract whether its state was updated by the call.
abizjak Jan 7, 2022
3714c92
Add a unit test for invoking a contract.
abizjak Jan 11, 2022
11cbbc6
Additional tests.
abizjak Jan 11, 2022
9d2d5a6
Fix bug in transferring failures to smart contracts.
abizjak Jan 11, 2022
76fadfe
Merge remote-tracking branch 'origin/main' into sync-calls
abizjak Jan 11, 2022
91a8e75
Add testing of error codes returned to contracts, and fix related iss…
abizjak Jan 15, 2022
2df594b
Streamline error handling a bit.
abizjak Jan 16, 2022
6e31609
Allow extra exports for V1 contracts, just don't use them.
abizjak Jan 16, 2022
0aa7fb1
Add some general documentation about contracts.
abizjak Jan 16, 2022
07da4ed
Documentation of invoking a contract.
abizjak Jan 16, 2022
8a0ff6b
Version module source as well in order to match versions.
abizjak Jan 16, 2022
8c18e07
Bump max transaction size in the network layer.
abizjak Jan 17, 2022
27607a8
Fix globalstate tests.
abizjak Jan 17, 2022
b7f5b6f
Improve JSON instances.
abizjak Jan 17, 2022
32d4a43
Improve documentation.
abizjak Jan 17, 2022
b15f4d8
Move InvokeContract types to Base
Bargsteen Jan 18, 2022
8ce1614
Fix tests after moving InvokeContract to Base
Bargsteen Jan 19, 2022
c6bc219
Return the updated balance to the resumed contract.
abizjak Jan 23, 2022
96eadd5
Documentation of some aspects of resume.
abizjak Jan 23, 2022
c136bfe
Retain P1-P3 semantics.
abizjak Jan 24, 2022
87c279b
Revise some naming for clarity.
abizjak Jan 25, 2022
bb910bc
Reverse order of returned events for V1 contracts, and fix bug in tra…
abizjak Jan 25, 2022
1bf1d68
Bump dependencies.
abizjak Jan 25, 2022
1d8ac05
Minor changes stemming from base update.
abizjak Feb 8, 2022
f414426
Merge remote-tracking branch 'origin/main' into sync-calls
abizjak Feb 8, 2022
24f76ff
Documentation, code style, and other minor fixes.
abizjak Feb 10, 2022
7da55e1
Document the new API.
abizjak Feb 11, 2022
23632f4
Bump base dependency after merge.
abizjak Feb 11, 2022
1342d1a
Improve documentation.
abizjak Feb 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion concordium-consensus/smart-contracts
Submodule smart-contracts updated 0 files
2 changes: 1 addition & 1 deletion concordium-consensus/src/Concordium/Scheduler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ handleContractUpdateV1 originAddr istance checkAndGetSender transferAmount recei
-- If execution of the contract succeeds resume.
-- Otherwise rollback the state and report that to the caller.
runInnerTransaction runSuccess >>= \case
Left err -> do -- execution failed, ignore the reject reason since V0 contract cannot return useful information
Left _ -> -- execution failed, ignore the reject reason since V0 contract cannot return useful information
go (resumeEvent False:interruptEvent:events) =<< runInterpreter (return . WasmV1.resumeReceiveFun rrdInterruptedConfig Nothing entryBalance WasmV1.MessageSendFailed Nothing)
Right evs -> do
-- Execution of the contract might have changed our own state. If so, we need to resume in the new state, otherwise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ invokeContract _ ContractContext{..} cm bs = do
-- cannot happen (this would mean out of block energy, and we set block energy no lower than energy),
-- but this is safe to do and not wrong
(Left Nothing, re) ->
return Failure{rcrReason = OutOfEnergy, rcrUsedEnergy = ccEnergy - re}
return Failure{rcrReason = OutOfEnergy, rcrReturnValue=Nothing, rcrUsedEnergy = ccEnergy - re}
-- Contract execution of a V0 contract failed with the given reason.
(Left (Just rcrReason), re) ->
return Failure{rcrUsedEnergy = ccEnergy - re,..}
return Failure{rcrUsedEnergy = ccEnergy - re,rcrReturnValue=Nothing,..}
-- Contract execution of a V0 contract succeeded with the given list of events
(Right (Left rcrEvents), re) ->
return Success{rcrReturnValue=Nothing,
Expand All @@ -163,6 +163,7 @@ invokeContract _ ContractContext{..} cm bs = do
(Right (Right (Left cf)), re) ->
return (Failure{
rcrReason = WasmV1.cerToRejectReasonReceive ccContract ccMethod ccParameter cf,
rcrReturnValue = WasmV1.returnValueToByteString <$> WasmV1.ccfToReturnValue cf,
rcrUsedEnergy = ccEnergy - re})
-- Contract execution of a V1 contract succeeded with the given return value.
(Right (Right (Right (rv, reversedEvents))), re) -> -- handleUpdateContractV1 returns events in reverse order
Expand Down
2 changes: 1 addition & 1 deletion concordium-grpc-api
37 changes: 36 additions & 1 deletion docs/grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Returns a JSON object representing the branches of the tree from the last finali
| `BlockHash` | base-16 encoded hash of a block (64 characters) |
| `TransactionHash` | base-16 encoded hash of a transaction (64 characters) |
| `ModuleRef` | base-16 encoded module reference (64 characters) |
| `Int` | integer |
| `Int` | integer |
| `EncryptionKey` | base-16 encoded string (192 characters) |
| `EncryptedAmount` | base-16 encoded string (384 characters) |
| `UTCTime` | UTC time. `yyyy-mm-ddThh:mm:ss[.sss]Z` (ISO 8601:2004(E) sec. 4.3.2 extended format) |
Expand Down Expand Up @@ -227,3 +227,38 @@ does not exist.

Get the source of the module as it was deployed on the chain. The response is a
byte array.

## InvokeContract : `BlockHash -> ContractContext -> ?InvokeContractResult`

Invoke a smart contract, returning any results. The contract is invoked in the
state at the end of a given block.

`ContractContext` is a record with fields
- `invoker: ?Address` &mdash; address of the invoker. If not supplied it
defaults to the zero account address
abizjak marked this conversation as resolved.
Show resolved Hide resolved
- `contract: ContractAddress` &mdash; address of the contract to invoke
- `amount: ?Amount` &mdash; an amount to invoke with. Defaults to 0 if not
supplied.
- `method: String` &mdash; name of the entrypoint to invoke. This needs to be
fully qualified in the format `contract.method`.
- `parameter: ?String` &mdash; parameter to invoke the method with, encoded in
hex. Defaults to empty if not provided.
- `energy: ?Number` &mdash; maximum amount of energy allowed for execution.
Defaults to 10_000_000 if not provided.

The return value is either `null` if either the block does not exist, or parsing
of any of the inputs failed. Otherwise it is a JSON encoded
`InvokeContractResult`.

This is a record with fields
- `tag: String` &mdash; eiether `"success"` or `"failure"`.
- `usedEnergy: Number` &mdash; the amount of NRG that was used during
execution
- `returnValue: ?String` &mdash; if invoking a V1 contract this is the return
value that was produced, if any (in case of runtime failure or out of energy
abizjak marked this conversation as resolved.
Show resolved Hide resolved
there is no return value). If invoking a V0 contract this field is not present.
- if `tag` is `"success"` the following fields are present
- `events: [Event]` &mdash; list of events generated as part of execution of
the contract
- if `tag` is `"failure"` then the following fields are present
- `reason: RejectReason` &mdash; encoding of a rejection reason