-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vm: implementation that supports account abstraction model (includes …
…signle key wallet) (#3229) related #3220 - state account extend with Template and State fields. stub accounts will have both Template and State as nil. When account is spawned with template - Template will store the address of the template, and State will store mutable and immutable state encoded using scale. - address when account is spawned address is computed as `sha256(template_address, spawn_args)`. this must be taken into an account when configuring the coinbase for a node. - validation and mempool tx id is computed as a `sha256(raw_tx)`, note that raw_tx is a full body of the transaction including signature. tx header can't be decoded without executing template code (specifically parse_payload and max_spend methods). in the upcoming pr - mempool will call into vm to initialize a validation flow (which includes parsing of the tx header). validation api is a 2 step process: - parse. returns transaction header that can be validated against conservative state - verify. executes templates verify method. it is assumed that this method costs much more than parse, so it makes sense to call it only if conservative validation succeeded. - applying transaction vm.Apply API method accepts layer id, transactions and rewards. Every transaction loads state, executes parse payload, initializes state and executed. Template/Handler API is specified in `genvm/core/types.go`. Transaction can be skipped for 3 reasons: - transaction is malformed (expectation is that such transactions should not be added to the block at all) - account is not spawned (same as a nonce mismatch) - nonce doesn't match the expected nonce of the account - can't cover max gas with the account balance If transaction is skipped it is returned back to the caller (presumably conservative state and the caller is free to do anything about it). Otherwise transaction is consumed and will pay fee to smeshers (in the followup pr for every consumed transaction we will store execution result). Logic for the fee distribution is not changed.
- Loading branch information
Showing
41 changed files
with
2,557 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,39 @@ | ||
package types | ||
|
||
import ( | ||
"github.com/spacemeshos/go-spacemesh/log" | ||
) | ||
|
||
//go:generate scalegen | ||
|
||
// Account represents account state at a certain layer. | ||
type Account struct { | ||
Layer LayerID | ||
Address Address | ||
Initialized bool | ||
Nonce uint64 | ||
Balance uint64 | ||
Template *Address | ||
State []byte | ||
} | ||
|
||
// NextNonce returns next expected nonce for the account state. | ||
func (a *Account) NextNonce() uint64 { | ||
if a.Template == nil { | ||
return 0 | ||
} | ||
return a.Nonce + 1 | ||
} | ||
|
||
// MarshalLogObject implements encoding for the account state. | ||
func (a *Account) MarshalLogObject(encoder log.ObjectEncoder) error { | ||
encoder.AddString("layer", a.Layer.String()) | ||
encoder.AddString("principal", a.Address.String()) | ||
encoder.AddUint64("nonce", a.Nonce) | ||
encoder.AddUint64("next nonce", a.NextNonce()) | ||
encoder.AddUint64("balance", a.Balance) | ||
if a.Template != nil { | ||
encoder.AddString("template", a.Template.String()) | ||
} | ||
return nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package types | ||
|
||
import "github.com/spacemeshos/go-scale" | ||
|
||
// Bytes64 is 64 byte array. | ||
type Bytes64 [64]byte | ||
|
||
// EncodeScale implements scale codec interface. | ||
func (b *Bytes64) EncodeScale(encoder *scale.Encoder) (int, error) { | ||
return scale.EncodeByteArray(encoder, b[:]) | ||
} | ||
|
||
// DecodeScale implements scale codec interface. | ||
func (b *Bytes64) DecodeScale(decoder *scale.Decoder) (int, error) { | ||
return scale.DecodeByteArray(decoder, b[:]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.