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 all 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:
os:
- ubuntu-22.04
- ubuntu-latest-arm-8-cores
- macos-13
# - macos-13
Copy link
Contributor

@poszu poszu Nov 7, 2024

Choose a reason for hiding this comment

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

It would be helpful to leave a note about why it's disabled and when it should be re-enabled:

Suggested change
# - macos-13
# Athena doesn't support Intel Mac
# - macos-13

- [self-hosted, macOS, ARM64, go-spacemesh]
# - windows-2022
steps:
Expand Down
32 changes: 16 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ run-name: Release ${{ github.ref_name }}
on:
push:
tags:
- '*'
- "*"

jobs:
build-and-upload:
Expand All @@ -16,15 +16,15 @@ jobs:
outname_sufix: "linux-amd64"
- os: ubuntu-latest-arm-8-cores
outname_sufix: "linux-arm64"
- os: macos-13
outname_sufix: "mac-amd64"
# - os: macos-13
# outname_sufix: "mac-amd64"
Comment on lines +19 to +20
Copy link
Contributor

@poszu poszu Nov 7, 2024

Choose a reason for hiding this comment

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

Ditto

Suggested change
# - os: macos-13
# outname_sufix: "mac-amd64"
# Athena doesn't support Intel Mac
# - os: macos-13
# outname_sufix: "mac-amd64"

- os: [self-hosted, macOS, ARM64, go-spacemesh]
outname_sufix: "mac-arm64"
- os: windows-2022
outname_sufix: "win-amd64"
permissions:
contents: 'read'
id-token: 'write'
contents: "read"
id-token: "write"
steps:
- shell: bash
run: echo "OUTNAME=go-spacemesh-${{ github.ref_name }}-${{ matrix.outname_sufix }}" >> $GITHUB_ENV
Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:
with:
project_id: ${{ secrets.GCP_WI_PROJECT_ID }}
workload_identity_provider: ${{ secrets.GCP_WI_PROVIDER_SA }}
service_account: ${{ secrets.GCP_WI_SA }}
service_account: ${{ secrets.GCP_WI_SA }}
token_format: access_token
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
Expand All @@ -107,9 +107,9 @@ jobs:
--endpoint-url https://${{ secrets.CLOUDFLARE_ACCOUNT_ID }}.r2.cloudflarestorage.com
--acl public-read --follow-symlinks
env:
AWS_ACCESS_KEY_ID: ${{ secrets.CLOUDFLARE_GO_SM_BUILDS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CLOUDFLARE_GO_SM_BUILDS_SECRET_ACCESS_KEY }}
AWS_REGION: us-east-1
AWS_ACCESS_KEY_ID: ${{ secrets.CLOUDFLARE_GO_SM_BUILDS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CLOUDFLARE_GO_SM_BUILDS_SECRET_ACCESS_KEY }}
AWS_REGION: us-east-1
- name: Install coreutils
if: ${{ matrix.os == 'macos-13' || matrix.os == '[self-hosted, macOS, ARM64, go-spacemesh]' }}
run: brew install coreutils
Expand All @@ -133,8 +133,8 @@ jobs:
runs-on: ubuntu-22.04
needs: build-and-upload
permissions:
contents: 'write'
id-token: 'write'
contents: "write"
id-token: "write"
steps:
- name: Download the artifacts
uses: actions/download-artifact@v4
Expand Down Expand Up @@ -164,7 +164,7 @@ jobs:
with:
project_id: ${{ secrets.GCP_WI_PROJECT_ID }}
workload_identity_provider: ${{ secrets.GCP_WI_PROVIDER_SA }}
service_account: ${{ secrets.GCP_WI_SA }}
service_account: ${{ secrets.GCP_WI_SA }}
token_format: access_token
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
Expand All @@ -187,16 +187,16 @@ jobs:
--endpoint-url https://${{ secrets.CLOUDFLARE_ACCOUNT_ID }}.r2.cloudflarestorage.com
--acl public-read --follow-symlinks
env:
AWS_ACCESS_KEY_ID: ${{ secrets.CLOUDFLARE_GO_SM_BUILDS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CLOUDFLARE_GO_SM_BUILDS_SECRET_ACCESS_KEY }}
AWS_REGION: us-east-1
AWS_ACCESS_KEY_ID: ${{ secrets.CLOUDFLARE_GO_SM_BUILDS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CLOUDFLARE_GO_SM_BUILDS_SECRET_ACCESS_KEY }}
AWS_REGION: us-east-1
- name: Create Release
uses: softprops/action-gh-release@v2
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
tag_name: ${{ github.ref_name }}
body: |
## Zip Files
- Windows amd64: https://go-spacemesh-release-builds.spacemesh.network/${{ github.ref_name }}/${{ env.OUTNAME_WIN_AMD64 }}.zip
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ else
ULIMIT := ulimit -n 4096;
endif

UNIT_TESTS ?= $(shell go list ./... | grep -v systest/tests | grep -v genvm/cmd)
UNIT_TESTS ?= $(shell go list ./... | grep -v systest/tests | grep -v vm/cmd)

export CGO_ENABLED := 1
export CGO_CFLAGS := $(CGO_CFLAGS) -DSQLITE_ENABLE_DBSTAT_VTAB=1
Expand Down
7 changes: 4 additions & 3 deletions Makefile-libs.Inc
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ 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_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)
ATHENA_SETUP_REV = v0.5.3
ATHENA_SETUP_RELEASE = v0.5.3
ATHENA_SETUP_ARTIFACT = athena_vmlib_$(ATHENA_SETUP_REV)_$(GOOS)_$(GOARCH).tar.gz
ATHENA_SETUP_ARTIFACT_URL ?= https://github.com/athenavm/athena/releases/download/$(ATHENA_SETUP_RELEASE)/$(ATHENA_SETUP_ARTIFACT)

ifeq ($(platform), windows)
POSTRS_SETUP_LIBS = post.h post.dll
Expand Down
78 changes: 52 additions & 26 deletions api/grpcserver/grpcserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ import (
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/datastore"
"github.com/spacemeshos/go-spacemesh/events"
vm "github.com/spacemeshos/go-spacemesh/genvm"
"github.com/spacemeshos/go-spacemesh/genvm/sdk"
"github.com/spacemeshos/go-spacemesh/genvm/sdk/wallet"
"github.com/spacemeshos/go-spacemesh/p2p"
"github.com/spacemeshos/go-spacemesh/p2p/peerinfo"
peerinfomocks "github.com/spacemeshos/go-spacemesh/p2p/peerinfo/mocks"
Expand All @@ -54,6 +51,11 @@ import (
"github.com/spacemeshos/go-spacemesh/sql/statesql"
"github.com/spacemeshos/go-spacemesh/system"
"github.com/spacemeshos/go-spacemesh/txs"
"github.com/spacemeshos/go-spacemesh/vm"
walletProgram "github.com/spacemeshos/go-spacemesh/vm/programs/wallet"
"github.com/spacemeshos/go-spacemesh/vm/sdk"
"github.com/spacemeshos/go-spacemesh/vm/sdk/wallet"
walletTemplate "github.com/spacemeshos/go-spacemesh/vm/templates/wallet"
)

const (
Expand Down Expand Up @@ -134,6 +136,7 @@ func dialGrpc(tb testing.TB, cfg Config) *grpc.ClientConn {
}

func TestMain(m *testing.M) {
os.Setenv("ATHENA_LIB_PATH", "../../build")
types.SetLayersPerEpoch(layersPerEpoch)

var err error
Expand All @@ -153,8 +156,16 @@ func TestMain(m *testing.M) {
os.Exit(1)
}

addr1 = wallet.Address(signer1.PublicKey().Bytes())
addr2 = wallet.Address(signer2.PublicKey().Bytes())
addr1, err = wallet.Address(*signer1.PublicKey())
if err != nil {
log.Println("failed to create address:", err)
os.Exit(1)
}
addr2, err = wallet.Address(*signer2.PublicKey())
if err != nil {
log.Println("failed to create address:", err)
os.Exit(1)
}

globalAtx = &types.ActivationTx{
PublishEpoch: postGenesisEpoch,
Expand Down Expand Up @@ -371,25 +382,29 @@ func (t *ConStateAPIMock) GetNonce(addr types.Address) (types.Nonce, error) {
return t.nonces[addr], nil
}

func (t *ConStateAPIMock) Validation(raw types.RawTx) system.ValidationRequest {
func (t *ConStateAPIMock) Validation(raw types.RawTx) system.ValidationRequestNew {
panic("dont use this")
}

func NewTx(nonce uint64, recipient types.Address, signer *signing.EdSigner) *types.Transaction {
tx := types.Transaction{TxHeader: &types.TxHeader{}}
tx.Principal = wallet.Address(signer.PublicKey().Bytes())
principal, err := wallet.Address(*signer.PublicKey())
if err != nil {
panic(err)
}
tx.Principal = principal
if nonce == 0 {
tx.RawTx = types.NewRawTx(wallet.SelfSpawn(signer.PrivateKey(),
0,
sdk.WithGasPrice(0),
))
tx2, err := wallet.Spawn(signer.PrivateKey(), 0, sdk.WithGasPrice(0))
if err != nil {
panic(err)
}
tx.RawTx = types.NewRawTx(tx2)
} else {
tx.RawTx = types.NewRawTx(
wallet.Spend(signer.PrivateKey(), recipient, 1,
nonce,
sdk.WithGasPrice(0),
),
)
tx2, err := wallet.Spend(signer.PrivateKey(), recipient, 1, nonce, sdk.WithGasPrice(0))
if err != nil {
panic(err)
}
tx.RawTx = types.NewRawTx(tx2)
Comment on lines +403 to +407
Copy link
Contributor

Choose a reason for hiding this comment

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

As NewTx is a test-only function, it could take tb testing.TB and then this could be simplified to:

Suggested change
tx2, err := wallet.Spend(signer.PrivateKey(), recipient, 1, nonce, sdk.WithGasPrice(0))
if err != nil {
panic(err)
}
tx.RawTx = types.NewRawTx(tx2)
tx2, err := wallet.Spend(signer.PrivateKey(), recipient, 1, nonce, sdk.WithGasPrice(0))
require.NoError(tb, err)
tx.RawTx = types.NewRawTx(tx2)

tx.MaxSpend = 1
}
return &tx
Expand Down Expand Up @@ -2315,7 +2330,8 @@ func TestTransactionsRewards(t *testing.T) {
t.Cleanup(cancel)
client := pb.NewGlobalStateServiceClient(dialGrpc(t, cfg))

address := wallet.Address(types.RandomNodeID().Bytes())
address, err := wallet.Address(*signing.NewPublicKey(types.RandomNodeID().Bytes()))
req.NoError(err)
weight := new(big.Rat).SetFloat64(18.7)
rewards := []types.CoinbaseReward{{Coinbase: address, Weight: types.RatNumFromBigRat(weight)}}

Expand Down Expand Up @@ -2379,22 +2395,32 @@ func TestVMAccountUpdates(t *testing.T) {
t.Cleanup(cleanup)

keys := make([]*signing.EdSigner, 10)
accounts := make([]types.Account, len(keys))
accounts := make([]types.Account, len(keys)+1)
const initial = 100_000_000
for i := range keys {
signer, err := signing.NewEdSigner()
require.NoError(t, err)
keys[i] = signer
addr, err := wallet.Address(*signing.NewPublicKey(signer.NodeID().Bytes()))
require.NoError(t, err)
accounts[i] = types.Account{
Address: wallet.Address(signer.NodeID().Bytes()),
Address: addr,
Balance: initial,
}
}
// add the wallet template account
accounts[len(accounts)-1] = types.Account{
Address: walletTemplate.TemplateAddress,
State: walletProgram.PROGRAM,
TemplateAddress: &walletTemplate.TemplateAddress,
}
require.NoError(t, svm.ApplyGenesis(accounts))
spawns := []types.Transaction{}
for _, key := range keys {
tx, err := wallet.Spawn(key.PrivateKey(), 0)
require.NoError(t, err)
spawns = append(spawns, types.Transaction{
RawTx: types.NewRawTx(wallet.SelfSpawn(key.PrivateKey(), 0)),
RawTx: types.NewRawTx(tx),
})
}
lid := types.GetEffectiveGenesis().Add(1)
Expand All @@ -2406,7 +2432,7 @@ func TestVMAccountUpdates(t *testing.T) {
client := pb.NewGlobalStateServiceClient(dialGrpc(t, cfg))
eg, ctx := errgroup.WithContext(ctx)
states := make(chan *pb.AccountState, len(accounts))
for _, account := range accounts {
for _, account := range accounts[:len(accounts)-1] {
stream, err := client.AccountDataStream(ctx, &pb.AccountDataStreamRequest{
Filter: &pb.AccountDataFilter{
AccountId: &pb.AccountId{Address: account.Address.String()},
Expand All @@ -2429,10 +2455,10 @@ func TestVMAccountUpdates(t *testing.T) {
spends := []types.Transaction{}
const amount = 100_000
for _, key := range keys {
tx, err := wallet.Spend(key.PrivateKey(), types.Address{1}, amount, 1)
require.NoError(t, err)
spends = append(spends, types.Transaction{
RawTx: types.NewRawTx(wallet.Spend(
key.PrivateKey(), types.Address{1}, amount, 1,
)),
RawTx: types.NewRawTx(tx),
})
}
_, _, err = svm.Apply(lid.Add(1), spends, nil)
Expand All @@ -2445,7 +2471,7 @@ func TestVMAccountUpdates(t *testing.T) {
require.Equal(t, 2, int(state.Counter))
require.Less(t, int(state.Balance.Value), initial-amount)
}
require.Equal(t, len(accounts), i)
require.Equal(t, len(accounts)-1, i)
}

func createAtxs(tb testing.TB, epoch types.EpochID, atxids []types.ATXID) []*types.ActivationTx {
Expand Down
2 changes: 1 addition & 1 deletion api/grpcserver/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type conservativeState interface {
GetMeshTransaction(types.TransactionID) (*types.MeshTransaction, error)
GetMeshTransactions([]types.TransactionID) ([]*types.MeshTransaction, map[types.TransactionID]struct{})
GetTransactionsByAddress(types.LayerID, types.LayerID, types.Address) ([]*types.MeshTransaction, error)
Validation(raw types.RawTx) system.ValidationRequest
Validation(raw types.RawTx) system.ValidationRequestNew
}

// syncer is the API to get sync status.
Expand Down
10 changes: 5 additions & 5 deletions api/grpcserver/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/grpcserver/transaction_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (

"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/events"
"github.com/spacemeshos/go-spacemesh/genvm/core"
"github.com/spacemeshos/go-spacemesh/p2p/pubsub"
"github.com/spacemeshos/go-spacemesh/sql"
"github.com/spacemeshos/go-spacemesh/sql/transactions"
"github.com/spacemeshos/go-spacemesh/vm/core"
)

// TransactionService exposes transaction data, and a submit tx endpoint.
Expand Down Expand Up @@ -78,7 +78,7 @@ func (s *TransactionService) ParseTransaction(
}
raw := types.NewRawTx(in.Transaction)
req := s.conState.Validation(raw)
header, err := req.Parse()
header, err := req.Parse(req.Cache())
if errors.Is(err, core.ErrNotSpawned) {
return nil, status.Error(codes.NotFound, "account is not spawned")
} else if errors.Is(err, core.ErrMalformed) {
Expand Down
Loading
Loading