-
Notifications
You must be signed in to change notification settings - Fork 9
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
API 2.0 #146
Comments
Modeling transaction receipt based on provided meta-data |
I think it must accept wasm compiled code and perform the validation. Compilation and local validation pre deploy should be part of the dev workflow done off-chain. There are many issues with having a transaction run a compiler and I don't think it is needed. @lrettig - thoughts on this? |
@lrettig @YaronWittenstein please have a look at TransactionReceipt - I'm trying to add the svm related features in a backward compatible way and I think it is feasible. I haven't added all the data Yaron listed above - we should go over this together. |
We also need to add status to blocks
It's a good question but I don't think this is the right place to discuss it as it's not directly relevant to the API design. Can we move it to the research forum? |
Please call this
This design doesn't seem to be fleshed out. What are the endpoints here, what do they accept and what do they return?
Does a template have a name? Must it? Feels unnecessary. The address it's deployed to should be its only, unique identifier. @YaronWittenstein ?
Let's call this
Why/how is this useful? Feels relatively arbitrary. As of a given point in time, the template either exists, or it doesn't. Not sure it matters when it was deployed.
Is there a more complete spec for what this will look like? What information does it contain, exactly?
What is this and how is it used?
I'm worried that this name will confuse people. We can use the term "App" internally if it makes sense to us, but I'd prefer to use a more familiar term in the API, such as "contract", "smartContract", "script", etc.
Note that only archive nodes will be able to accept a
As above - do we really need this? Feels unnecessary.
I prefer
Add: "...if any." (not all smart contracts are deployed from a template, right?)
Is this a state root? Is this necessary?
As above, is this necessary? How/why is it used?
What is this and how is it used?
I thought SVM will also be responsible for simple coin tx, no?
Do we allow these transactions to run arbitrary logic/make arbitrary state changes, or not? This should probably also include the destination address of a deployed template (if any), and txid, payor/source
Can we use a more generic name here, too? E.g., "deploy contract" Shouldn't this also include the address of the template (if any) and the address of the newly-deployed contract (if any)? Also, txid, payor/source
I'm not sure we will allow the constructor to have any return data, @YaronWittenstein ?
Ethereum logs include a "name" field, in addition to the |
@lrettig - I think it will be helpful if you look at the proposed grpc changes - they are a bit more coherent - here what we have is mostly an initial survey of everything we need to consider, but the api proposed changes are refactored differently mainly to support backward compatibility and reduce the number of types that an api user needs to comprehend to use it. |
Sure but for now we want to progress with the safe option of needing accepting wasm compiled code. |
That's not the design pattern we talked about for state in the various smipps. We have discussed that full nodes keep state for n layers in the past and archive nodes since genesis. So the api should support this and node will return data if it has it which is based on the layer number, the current layer and the node type. |
Good feedback. Make sense. Check recent commit for implementation of this. |
Added name to log entries. So I think we are ready to do a proper design review on the proposed api changes in the 0.3 branch. Incorporated most feedback that required changes. Some of the feedback issues are already addressed in the current api design. |
We have a draft proposal for api changes that implement most requirements here in this branch: https://github.com/spacemeshos/api/tree/sm0.3-update/proto/spacemesh/v1 |
2 PRs to resolve this issue are waiting for review: #156 #149 |
Additional Functionality
Below are API changes and addition required due to support the new 0.3 features such as
self healing
andSpacemesh Apps
.MeshService
Layer Status
Update layer statuses due to self healing related changes. (see #144)
Activation Layer
Disassociate activation from a specific layer and associate it with a specific epoch. (see #132, #133)
GlobalStateService
GetStateRoot
Expects:
layer
(layer_num
) - This parameter optional and defaults to the most recentlayer
of the Node.The API returns:
layer_num
- Thelayer_num
used to process the requeststate
- theState
(the Global State root hash) associated with thelayer_num
.Namespaces
Supports state namespaces -
A namespace
andTemplates namespace
.Get Template
The API expects a Template
Address
and it will return back the following:Template
(`Address) - The value supplied to the requestName
(String
)Author
(Address
)DeployedAt Layer
(layer_num
)The
layer_num
at which theTemplate
has been deployed atTx Id
(An array of 32 bytes - needs to review again the number of bytes)The id of the transaction that deployed the template (a transaction of type
deploy template
)Code
(Binary Wasm)This is a blob of data that can be translated to Wasm textual representation of inspection (at the client-side)
Schema
Right now we only support fixed-length variables for an App's storage.
So for now, the schema will be an Array of fixed-length variables.
Each variable returned will specify:
id
- an integer serving as a unique identifier within the App's variables (fits into 2 bytes)name
-String
type
A
type
can be a primitive:i8 / u8 / i16 / i16/ u32 / i32 / u64 / i64 / bool / Amount / Address
or it can be an
Array
ofprimitives
for example:Amount
oflength = 3
GetAllTemplates
In Genesis, we only deploy the Vaults templates (the exact number of templates will be within 1 to 3 probably)
We'll be able to return the whole
Template
s in a single call.Since we want to be future compatible when there will be more
Template
(created not as part of Genesis),we'd like the API to support pagination from the start.
The API will have pagination, so each request will contain:
offset
- anu32
integer.count
- how manyTemplate
s to returnreturnCode
- optional. we want to return acode
for each returnedTemplate
(defaults to false)The API will return:
offset
(u32
) - The value supplied to the requestcount
(u32
) - The value supplied to the requesthasMore
(bool
) - Whether there're more templatestotal
(u32
) - The total number of templates[Template]
- an Array where each item is aTemplate
of the same format asGet Template
above.Code
- This is a blob of data that can be translated to Wasm textual representation of inspection (at the client-side).This field is returned when `returnCode = true in the request
App
Get App Variable
The API expects:
App
(Address
)Layer
(layer_num
) - This parameter will be optional. It defaults to the most recentlayer
.variable id
- an integer serving as a unique identifier within the App's variables.The response will be:
App
- TheAddress
supplied to the requestLayer
- Thelayer
of theApp
used for processing the requestid
- Thevariable id
supplied to the requestName
-String
Spawner
- TheAddress
of the Account that spawned theApp
Template
(Address
)The
Address
of theTemplate
that theApp
has been spawned fromState
- TheState
associated with processedlayer
SpawnedAt Layer
(layer_num
)The
layer_num
at which theApp
has been spawnedTx Id
(An array of 32 bytes - needs to review again the number of bytes)type
- see above the options fortype
value
i8
-i8
numberu8
-u8
numberi16
-i16
numberu16
-u16
numberu32
-u32
numberi32
-i32
numberi64
-i64
numberu64
-u64
numberbool
-true / false
Amount
-u64
numberAddress
- 20 bytesGet App
The API expects:
App
(Address
)Layer
(layer_num
) - This parameter will be optional. It defaults to the most recentlayer
.The value of the
layer
will affect the values of the returnedvariables
.The API will return:
App
- TheAddress
supplied to the requestLayer
- Thelayer
of theApp
used for processing the requestName
(String
)Spawner
- TheAddress
of the Account that spawned theApp
Template
(Address
)The
Address
of theTemplate
that theApp
has been spawned fromState
- TheState
associated with processedlayer
SpawnedAt Layer
(layer_num
)The
layer_num
at which theApp
has been spawnedTx Id
(An array of 32 bytes - needs to review again the number of bytes)The id of the transaction that spawned the app (a transaction of type
spawn app
)variables
(an Array ofvariable
and their values)Each
variable
will be returned as specified above underGet App Variable
Compatibility notes: these changes can be backward compatible by adding new methods and depreciating older methods (such as AccountDataQuery) while still supporting them.
Receipts
SVM executes 3 types of transactions:
deploy template
/spawn app
/execute app
.Each kind of transaction has a corresponding
Receipt
type.Following are the high-level specifications of the Receipts.
Deploy Template
ReceiptThe
Deploy Template
receipt should be created after executing adeploy template
transaction.Each
Receipt
will contain the following:version
(u16
)success
(bool
) - Whether thedeploy template
transaction has succeedederror
- optional. Whensuccess=false
it will contain the error that occurred (see:Receipt Error
later)gas_used
(u64
) - The gas units used for executing the transaction.logs
- seeReceipt Logs
Spawn App
Receiptversion
(u16
)success
(bool
) - Whether thespawn app
transaction has succeedederror
- optional. Whensuccess=false
it will contain the error that occurred (see:Receipt Error
later)app
(Address
) - The newly spawned appAddress
. Relevant only whensuccess=true
init_state
(State
) - The newly spawned app initialState
. Relevant only whensuccess=true
return_data
(bytes) - Thereturn data
is thespawn app ctor
execution output.The encoding of the returned data is determined by the code running. The best practice is to use the same ABI used
when encoding input
CallData
of the ctor input.@avive in order to decode at the client the
return data
the client needs to write ad-hoc code to the ABI used.Right now, the Vaults can use the
svm_codec.wasm
for achieving that easily. This file is generated after each SVM successful CI run (can be taken from the CI artifacts).gas_used
(u64
) - The gas units used for executing the transaction.logs
- seeReceipt Logs
The
Spawn App
receipt should be created after executing aspawn template
transaction.Each
Receipt
will contain the following:Execute App
Receiptversion
(u16
)success
(bool
) - Whether theexec app
transaction has succeedederror
- optional. Whensuccess=false
it will contain the error that occurred (see:Receipt Error
later)new_state
(State
) - The newly executed appState
. Relevant only whensuccess=true
return_data
(bytes) - Thereturn data
is theexecuted function
output.The encoding of the returned data is determined by the code running. The best practice is to use the same ABI used
when encoding input
CallData
of the ctor input.@avive in order to decode at the client the
return data
the client needs to write ad-hoc code to the ABI used.Right now, the Vaults can use the
svm_codec.wasm
for achieving that easily. This file is generated after each SVM successful CI run (can be taken from the CI artifacts).gas_used
(u64
) - The gas units used for executing the transaction.logs
- seeReceipt Logs
Receipt Logs
Each Receipt will be accompanied with zero or more logs.
It's very useful for debugging and extracting events that have happened during the running of the transaction.
It's important to stress, that logs are allowed to be returned when transaction fails.
So if a program ran and accumulate 5 logs before panicking - these 5 log entries will be attached to the Receipt as well.
Each log entry contains:
msg
(bytes) - usually it'll be a valid UTF-8 string, but it depends on the code executedcode
(u8
) - serving as the logging level / application tagReceipt Error
Each transaction might fail. In that case, the
success
field of the matching Receipt will be set tofalse
and an
error
will be returned.OOG
(short forOut-Of-Gas
)TemplateNotFound(TemplateAddress)
-When trying to spawn an app of non-existing template. In general, such case should never happen unless there is a bug
in the validation phase (normally, such transactions should have been discarded from the
mempool
earlier)AppNotFound(Address)
When trying to execute an app transaction but app is not found.
As explained above - proper validation should avoid that from happening from the first place
CompilationFailed
app
(Address
) - Theaddress
template
(TemplateAddress`)message
(String)@avive we need to discuss whether
deploy template
should compile the code or suffice with basic validation of the Wasm codeas it's done right now. (using the
wasmparser
crate). In that case theapp
field will become optional.InstantiationFailed
- Didn't manage to create anInstance
to runapp_addr
(Address
)template_addr
(TemplateAddress`)message
(String
)There is one easy way I can think of right now and it's calling a function with wrong parameters. Violation of the function signature is something I think we can avoid since we always pass data to a function via the
CallData
mechanism.Nonetheless, we still need to support that error in our API.
FuncNotFound
- Invalid input, function has not been foundapp_addr
(Address
)template_addr
(TemplateAddress`)func
(String
) - The name of the function not foundFuncFailed
- function has failed while running (e.g panicking)app_addr
(Address
)template_addr
(TemplateAddress`)func
(String
) - The name of the failing functionmsg
(String
) - An error message that we managed to grab when failingAPI Versioning
If we can add the new features and make the changes in a fully backward compatible way then we can have these changes in
v0.1.2
. Otherwise, these changes will be in APIv0.2.0
.TBD / WIP
We need to consider additional API capabilities (which might be non-backward compatible):
The text was updated successfully, but these errors were encountered: