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

Athena: Initial POC integration #6380

Open
wants to merge 73 commits into
base: athena-poc
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
a0bd91b
Switch node VM to athena
lrettig Oct 8, 2024
95620c3
Remove unused context methods and data items
lrettig Oct 8, 2024
2baf0c6
Ignore athena compressed artifacts in top dir
lrettig Oct 8, 2024
69c33c7
Remove some more unused methods
lrettig Oct 8, 2024
e134441
Linter
lrettig Oct 8, 2024
2e94bda
Add pubkey back to wallet template
lrettig Oct 8, 2024
b764ab8
Continue to clean up tx handling
lrettig Oct 9, 2024
92be516
More cleanup
lrettig Oct 9, 2024
d4eab1a
Continuing rewrite of VM parse code (WIP)
lrettig Oct 10, 2024
c91bdda
Ongoing integration work (WIP)
lrettig Oct 18, 2024
b3f4865
Integrate latest Athena release
lrettig Oct 18, 2024
7e8bdd6
Refactor Athena template code
lrettig Oct 21, 2024
510306e
First draft of Call implementation for host
lrettig Oct 21, 2024
11cfdcc
First working e2e host test
lrettig Oct 21, 2024
dab770c
VM execution WIP
lrettig Oct 22, 2024
638b604
Finish initial handler Exec implementation
lrettig Oct 22, 2024
e2d55b8
Checkpoint: rewriting template to use VM
lrettig Oct 23, 2024
d5b947d
MaxSpend test is working
lrettig Oct 23, 2024
d3e6bd7
Checkpoint: working on TestVerify
lrettig Oct 23, 2024
28a6cc5
Checkpoint: debugging verify test
lrettig Oct 24, 2024
cb0b07a
Spawn test is working
lrettig Oct 24, 2024
6bcd565
TestVerify is passing
lrettig Oct 24, 2024
9b5543d
Remove genesisID from tx generation for now
lrettig Oct 24, 2024
52e7cf6
Checkpoint: refactoring parse
lrettig Oct 25, 2024
1235f36
Upgrade athena bindings to v0.5.0
lrettig Oct 25, 2024
b847c32
Rewrite VM parse logic
lrettig Oct 25, 2024
2ad4adf
Add scale limit for payload
lrettig Oct 25, 2024
9821f88
Update mocks
lrettig Oct 25, 2024
c8ed09e
Major cleanup
lrettig Oct 25, 2024
148a5d8
Cleanup based on linter
lrettig Oct 25, 2024
ab98656
More linting
lrettig Oct 25, 2024
cc86c7a
make generate
lrettig Oct 25, 2024
e9d8f87
Cleaning up VM tests
lrettig Oct 26, 2024
4520187
Add draft athena testnet config
lrettig Oct 26, 2024
134153d
Add simple test vector generator
lrettig Oct 26, 2024
3bd8e0f
Add genesis wallet template with balance
lrettig Oct 26, 2024
75b4e84
Checkpoint: working on spawn transaction logic
lrettig Oct 28, 2024
a9f35b1
Fix Principal calculation
lrettig Oct 29, 2024
14e842a
Upgrade Athena to 0.5.2
lrettig Oct 29, 2024
27e421d
Refactor state management in context
lrettig Oct 30, 2024
d06371e
More work on VM state management
lrettig Oct 30, 2024
29bf0e3
Fix host state issue
lrettig Oct 30, 2024
363d39d
First VM test is passing
lrettig Oct 31, 2024
01bf8b1
Review feedback
lrettig Oct 31, 2024
2b329db
Working on host tests
lrettig Oct 31, 2024
71314f8
Still working on VM tests
lrettig Oct 31, 2024
5a26e63
Enable a few more tests
lrettig Oct 31, 2024
08bcf38
Improve gas arithmetic
lrettig Oct 31, 2024
7020530
Enable a few more tests
lrettig Nov 1, 2024
cabff43
Fix duplicate spawn tx test
lrettig Nov 1, 2024
4b6d041
Enable next test (still failing)
lrettig Nov 1, 2024
a4a8c74
Comment and require description
lrettig Nov 1, 2024
ae03e35
Don't refund gas for failed txs
lrettig Nov 4, 2024
bd9f830
Remove non-self spawn from tests
lrettig Nov 4, 2024
fdcdd3b
Properly handle another spawn issue
lrettig Nov 4, 2024
9063cb8
All vm tests passing!
lrettig Nov 4, 2024
1f9000c
go generate
lrettig Nov 4, 2024
1ce6abe
Linting
lrettig Nov 4, 2024
f08acff
Remove unsupported macos-13
lrettig Nov 4, 2024
1a6d002
Fix TestVMAccountUpdates
lrettig Nov 4, 2024
3a7dd34
Fix TestParseTransactions
lrettig Nov 4, 2024
d48c6a4
txs, api tests passing
lrettig Nov 4, 2024
3f3ae92
Remove remaining genvm references
lrettig Nov 4, 2024
67852f2
Fix vm host test
lrettig Nov 4, 2024
294fe6b
Fix wallet template tests
lrettig Nov 4, 2024
1d2f6a7
More linting
lrettig Nov 4, 2024
df9ac86
Fix blocks tests
lrettig Nov 5, 2024
6e7942f
Fix TransactionService test
lrettig Nov 5, 2024
bb5dc73
Fix transaction tests
lrettig Nov 5, 2024
433daf5
Use nightly athena release
lrettig Nov 5, 2024
0f8e560
bump athena to v0.5.3
poszu Nov 15, 2024
4d404cb
reenable building on macos-13
poszu Nov 15, 2024
69a90c5
Revert "reenable building on macos-13"
poszu Nov 15, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ temp.js

*.out
*.test
*.tar.gz
*.zip

/go-spacemesh
Expand Down
2 changes: 1 addition & 1 deletion Makefile-libs.Inc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ POSTRS_PROFILER_URL ?= https://github.com/spacemeshos/post-rs/releases/download/
POSTRS_SERVICE_ZIP = post-service-$(platform)-v$(POSTRS_SETUP_REV).zip
POSTRS_SERVICE_URL ?= https://github.com/spacemeshos/post-rs/releases/download/v$(POSTRS_SETUP_REV)/$(POSTRS_SERVICE_ZIP)

ATHENA_SETUP_REV = 0.4.1
ATHENA_SETUP_REV = 0.5.0
ATHENA_SETUP_ARTIFACT = athena_vmlib_v$(ATHENA_SETUP_REV)_$(GOOS)_$(GOARCH).tar.gz
ATHENA_SETUP_ARTIFACT_URL ?= https://github.com/athenavm/athena/releases/download/v$(ATHENA_SETUP_REV)/$(ATHENA_SETUP_ARTIFACT)

Expand Down
2 changes: 1 addition & 1 deletion common/types/account_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ package types
// StorageItem represents a single item of account storage.
type StorageItem struct {
Key [32]byte
Value Hash32
Value [32]byte
}
34 changes: 27 additions & 7 deletions common/types/transaction_header.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
package types

import "go.uber.org/zap/zapcore"
import (
"encoding/hex"
"fmt"

"go.uber.org/zap/zapcore"
)

//go:generate scalegen

// TxHeader is a transaction header, with some of the fields defined directly in the tx
// and the rest is computed by the template based on immutable state and method arguments.
type TxHeader struct {
Principal Address
Principal Address

// TODO(lane): TemplateAddress and Method are unused by the Athena VM, and should be removed.
TemplateAddress Address
Method uint8
Nonce Nonce
LayerLimits LayerLimits
MaxGas uint64
GasPrice uint64
MaxSpend uint64

Nonce Nonce
LayerLimits LayerLimits
MaxGas uint64
GasPrice uint64
MaxSpend uint64

// Payload is opaque to the host (go-spacemesh), and is passed into and interpreted by the VM.
Payload []byte
}

// Fee is a MaxGas multiplied by a GasPrice.
Expand All @@ -26,16 +37,25 @@ func (h *TxHeader) Fee() uint64 {
func (h *TxHeader) Spending() uint64 {
return h.Fee() + h.MaxSpend
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
lrettig marked this conversation as resolved.
Show resolved Hide resolved

// MarshalLogObject implements encoding for the tx header.
func (h *TxHeader) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
payloadHash := hex.EncodeToString(h.Payload)
encoder.AddString("principal", h.Principal.String())
encoder.AddUint64("nonce_counter", h.Nonce)
encoder.AddUint32("layer_min", h.LayerLimits.Min)
encoder.AddUint32("layer_max", h.LayerLimits.Max)
encoder.AddUint64("max_gas", h.MaxGas)
encoder.AddUint64("gas_price", h.GasPrice)
encoder.AddUint64("max_spend", h.MaxSpend)
encoder.AddString("payload",
fmt.Sprintf("%s... (len %d)", payloadHash[:min(len(payloadHash), 5)], len(h.Payload)))
return nil
}

Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ go 1.23.2
require (
cloud.google.com/go/storage v1.44.0
github.com/ALTree/bigfloat v0.2.0
github.com/athenavm/athena/ffi/athcon/bindings/go v0.4.1
github.com/ChainSafe/gossamer v0.9.0
github.com/athenavm/athena/ffi/athcon/bindings/go v0.4.2-0.20241021224807-578f0f40e8a7
lrettig marked this conversation as resolved.
Show resolved Hide resolved
github.com/chaos-mesh/chaos-mesh/api v0.0.0-20240930092556-24ddcc087ee2
github.com/cosmos/btcutil v1.0.5
github.com/go-llsqlite/crawshaw v0.5.5
Expand Down Expand Up @@ -119,7 +120,7 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
Expand Down Expand Up @@ -240,7 +241,7 @@ require (
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.24.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/tools v0.25.0 // indirect
Expand Down
16 changes: 10 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGy
github.com/ALTree/bigfloat v0.2.0 h1:AwNzawrpFuw55/YDVlcPw0F0cmmXrmngBHhVrvdXPvM=
github.com/ALTree/bigfloat v0.2.0/go.mod h1:+NaH2gLeY6RPBPPQf4aRotPPStg+eXc8f9ZaE4vRfD4=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/ChainSafe/gossamer v0.9.0 h1:Xj2oRO+5JFIpE3qkC9L8pyR1fxTPv5fTGwvvD2BnmQQ=
github.com/ChainSafe/gossamer v0.9.0/go.mod h1:V/ePNNEpATpoP8IS65suyVT05waGwQT/EtyhMhqOTKk=
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.24.1 h1:pB2F2JKCj1Znmp2rwxxt1J0Fg0wezTMgWYk5Mpbi1kg=
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.24.1/go.mod h1:itPGVDKf9cC/ov4MdvJ2QZ0khw4bfoo9jzwTJlaxy2k=
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.48.1 h1:UQ0AhxogsIRZDkElkblfnwjc3IaltCm2HUMvezQaL7s=
Expand All @@ -57,8 +59,8 @@ github.com/anacrolix/sync v0.3.0 h1:ZPjTrkqQWEfnYVGTQHh5qNjokWaXnjsyXTJSMsKY0TA=
github.com/anacrolix/sync v0.3.0/go.mod h1:BbecHL6jDSExojhNtgTFSBcdGerzNc64tz3DCOj/I0g=
github.com/anacrolix/tagflag v0.0.0-20180109131632-2146c8d41bf0/go.mod h1:1m2U/K6ZT+JZG0+bdMK6qauP49QT4wE5pmhJXOKKCHw=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/athenavm/athena/ffi/athcon/bindings/go v0.4.1 h1:ASBAzSJJZIzcfzsG1hjxI6L6Rt5TohIR8Fd6Yf5hRZQ=
github.com/athenavm/athena/ffi/athcon/bindings/go v0.4.1/go.mod h1:Vc27TBhU0XvcksDXiPgl5hJCswkUS3V9tG0sGh2jAhg=
github.com/athenavm/athena/ffi/athcon/bindings/go v0.4.2-0.20241021224807-578f0f40e8a7 h1:MqHp+mDnvT9A5NnDIxufYX4uobkoO43obiAmk0YAPLQ=
github.com/athenavm/athena/ffi/athcon/bindings/go v0.4.2-0.20241021224807-578f0f40e8a7/go.mod h1:dgoxFG6b5kBESS03ZC4WSi3vzLcmTTchqwPOVFYiFTc=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o=
Expand Down Expand Up @@ -213,8 +215,9 @@ github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk=
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/btree v0.0.0-20180124185431-e89373fe6b4a/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
Expand Down Expand Up @@ -624,8 +627,9 @@ github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic
github.com/slok/go-http-metrics v0.13.0 h1:lQDyJJx9wKhmbliyUsZ2l6peGnXRHjsjoqPt5VYzcP8=
github.com/slok/go-http-metrics v0.13.0/go.mod h1:HIr7t/HbN2sJaunvnt9wKP9xoBBVZFo1/KiHU3b0w+4=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
github.com/smartystreets/assertions v1.13.0 h1:Dx1kYM01xsSqKPno3aqLnrwac2LetPvN23diwyr69Qs=
github.com/smartystreets/assertions v1.13.0/go.mod h1:wDmR7qL282YbGsPy6H/yAsesrxfxaaSlJazyFLYVFx8=
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s=
github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg=
github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM=
Expand Down Expand Up @@ -866,8 +870,8 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
Expand Down
2 changes: 1 addition & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import (
"github.com/spacemeshos/go-spacemesh/datastore"
"github.com/spacemeshos/go-spacemesh/events"
"github.com/spacemeshos/go-spacemesh/fetch"
vm "github.com/spacemeshos/go-spacemesh/genvm"
"github.com/spacemeshos/go-spacemesh/hare3"
"github.com/spacemeshos/go-spacemesh/hare3/compat"
"github.com/spacemeshos/go-spacemesh/hare3/eligibility"
Expand Down Expand Up @@ -90,6 +89,7 @@ import (
"github.com/spacemeshos/go-spacemesh/timesync/peersync"
"github.com/spacemeshos/go-spacemesh/tortoise"
"github.com/spacemeshos/go-spacemesh/txs"
"github.com/spacemeshos/go-spacemesh/vm"
)

const (
Expand Down
97 changes: 9 additions & 88 deletions vm/core/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// Context serves 2 purposes:
// - maintains changes to the system state, that will be applied only after successful execution
// - maintains changes to the system state, that will be applied only after succesful execution
// - accumulates set of reusable objects and data.
type Context struct {
Registry HandlerRegistry
Expand Down Expand Up @@ -85,14 +85,14 @@ func (c *Context) Spawn(args scale.Encodable) error {
return fmt.Errorf("%w: spawn is called with unknown handler", ErrInternal)
}
buf := bytes.NewBuffer(nil)
instance, err := handler.New(args)
if err != nil {
return fmt.Errorf("%w: %w", ErrMalformed, err)
}
_, err = instance.EncodeScale(scale.NewEncoder(buf))
if err != nil {
return fmt.Errorf("%w: %w", ErrInternal, err)
}
// instance, err := handler.New(args)
// if err != nil {
// return fmt.Errorf("%w: %w", ErrMalformed, err)
// }
// _, err = instance.EncodeScale(scale.NewEncoder(buf))
// if err != nil {
// return fmt.Errorf("%w: %w", ErrInternal, err)
// }
account.State = buf.Bytes()
account.TemplateAddress = &c.Header.TemplateAddress
c.change(account)
Expand Down Expand Up @@ -127,54 +127,6 @@ func (c *Context) transfer(from *Account, to Address, amount, max uint64) error
return nil
}

// Relay call to the remote account.
func (c *Context) Relay(remoteTemplate, address Address, call func(Host) error) error {
account, err := c.load(address)
if err != nil {
return err
}
if account.TemplateAddress == nil {
return ErrNotSpawned
}
if *account.TemplateAddress != remoteTemplate {
return fmt.Errorf(
"%w: %s != %s",
ErrTemplateMismatch,
remoteTemplate.String(),
account.TemplateAddress.String(),
)
}
handler := c.Registry.Get(remoteTemplate)
if handler == nil {
panic("template of the spawned account should exist in the registry")
}
template, err := handler.Load(account.State)
if err != nil {
return err
}

remote := &RemoteContext{
Context: c,
remote: account,
handler: handler,
template: template,
}
if err := call(remote); err != nil {
return err
}
// ideally such changes would be serialized once for the whole block execution
// but it requires more changes in the cache, so can be done as an optimization
// if it proves meaningful (most likely wont)
buf := bytes.NewBuffer(nil)
encoder := scale.NewEncoder(buf)
if _, err := template.EncodeScale(encoder); err != nil {
return fmt.Errorf("%w: %w", ErrInternal, err)
}
account.State = buf.Bytes()
c.change(account)
return nil
}

// Consume gas from the account after validation passes.
func (c *Context) Consume(gas uint64) (err error) {
amount := gas * c.Header.GasPrice
Expand Down Expand Up @@ -253,34 +205,3 @@ func (c *Context) change(account *Account) {
}
c.changed[account.Address] = account
}

// RemoteContext ...
type RemoteContext struct {
*Context
remote *Account
handler Handler
template Template
}

// Balance returns the remote account balance.
func (r *RemoteContext) Balance() uint64 {
return r.remote.Balance
}

// Template ...
func (r *RemoteContext) Template() Template {
return r.template
}

// Handler ...
func (r *RemoteContext) Handler() Handler {
return r.handler
}

// Transfer ...
func (r *RemoteContext) Transfer(to Address, amount uint64) error {
if err := r.transfer(r.remote, to, amount, amount); err != nil {
return err
}
return nil
}
Loading
Loading