Skip to content

Commit

Permalink
Add WS support (#158)
Browse files Browse the repository at this point in the history
* reduce `tstate` map copies + distinguish between empty/non-existent values (#142)

* update runners

* reduce copies

* remove err check

* more cleanup

* comments

* simplify revert logic

* cleanup some tests

* fix remove rollback case

* add pending changes

* add state ops metrics

* save results of previously generated state keys

* run load test on different levels

* nit

* continue if failure

* always continue on error

* fix continue on error

* improve changes estimate

* Update to AvalancheGo@v1.10.0 (#147)

* update to avalanchego@v1.10.0

* updaate timeouts

* add protection on sync tests

* Add load test to env (#151)

* update env

* add conditional env

* add release to conditional run

* Try `env` (#152)

* try env

* add new env

* use correct spec

* try again

* just make long-ci plain for now

* update jobs

* typo

* Update to ANR@1.4.1 (#149)

* use anr 1.4.0

* check e2e fix

* nit

* try e2e fix

* empty

* empty

* empty

* fix add node tracked subnets

* lint

* depend on anr main

* fix version in e2e

* update to v1.4.1

---------

Co-authored-by: Patrick O'Grady <prohb125@gmail.com>

* add ecosystem badge (#155)

* save refactor progress

* basic compliation

* remove vm/streaming

* fix pubsub tests

* integration working

* lint utils

* move things around

* jsonrpc compiles

* jsonrpc client compiles

* websocket client works

* vm compiling

* rename related files

* continued cleanup

* outlining changes

* move orderbook

* work on more dependencies

* cleanup jsonrpc server

* jsonrpc client cleanup

* more setup

* cleanup RPC in vm

* remove import cycle

* move handler init

* more client cleanup

* layout changes needed to finish client

* add more TODOs

* fix client

* nit

* handle errors from packers

* add max conns todo

* nits

* cleanup action

* fix build warnings

* nits

* load compiles

* use protect data struct

* integration compiles

* e2e compiles

* lint

* cleanup client init

* remove unused metrics

* decrease size of pending channels

* fix websocket client

---------

Co-authored-by: felipemadero <felipe.madero@gmail.com>
  • Loading branch information
patrick-ogrady and felipemadero authored Apr 30, 2023
1 parent 67bdfb3 commit 697b3e3
Show file tree
Hide file tree
Showing 67 changed files with 2,140 additions and 1,767 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
Lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 30
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
39 changes: 29 additions & 10 deletions .github/workflows/tokenvm-load-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ on:
pull_request:

jobs:
tests:
cond-tests:
environment: 'long-ci'
if: ${{ github.ref != 'refs/heads/main'}}
strategy:
matrix:
level: [v1, v2, v3] # v4 is not supported
runs-on:
labels: ubuntu-latest-16-cores
timeout-minutes: 30
labels: ubuntu-20.04-32
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v3
# - name: Install fio
# run: sudo apt-get -y install fio
# - name: Run disk tests
# working-directory: ./examples/tokenvm
# shell: bash
# run: scripts/tests.disk.sh
- name: Set up Go
uses: actions/setup-go@v3
with:
Expand All @@ -31,7 +30,27 @@ jobs:
- name: Run load tests
working-directory: ./examples/tokenvm
shell: bash
run: scripts/tests.load.sh
run: GOAMD64=${{ matrix.level }} scripts/tests.load.sh
main-tests:
if: ${{ github.ref == 'refs/heads/main'}}
strategy:
matrix:
level: [v1, v2, v3] # v4 is not supported
runs-on:
labels: ubuntu-20.04-32
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.20"
check-latest: true
- name: Run load tests
working-directory: ./examples/tokenvm
shell: bash
run: GOAMD64=${{ matrix.level }} scripts/tests.load.sh

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand Down
52 changes: 49 additions & 3 deletions .github/workflows/tokenvm-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,56 @@ on:
pull_request:

jobs:
release:
cond-release:
# We build with 20.04 to maintain max compatibility: https://github.com/golang/go/issues/57328
runs-on: ubuntu-20.04-16-cores
runs-on: ubuntu-20.04-32
environment: 'long-ci'
if: ${{ github.ref != 'refs/heads/main'}}
steps:
- name: Git checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: "1.20"
check-latest: true
- name: Set up arm64 cross compiler
run: sudo apt-get -y install gcc-aarch64-linux-gnu
- name: Checkout osxcross
uses: actions/checkout@v2
with:
repository: tpoechtrager/osxcross
path: osxcross
- name: Build osxcross
run: |
sudo apt-get -y install clang llvm-dev libxml2-dev uuid-dev libssl-dev bash patch make tar xz-utils bzip2 gzip sed cpio libbz2-dev
cd osxcross
wget https://github.com/joseluisq/macosx-sdks/releases/download/12.3/$MACOS_SDK_FNAME -O tarballs/$MACOS_SDK_FNAME
echo $MACOS_SDK_CHECKSUM tarballs/$MACOS_SDK_FNAME | sha256sum -c -
UNATTENDED=1 ./build.sh
echo $PWD/target/bin >> $GITHUB_PATH
env:
MACOS_SDK_FNAME: MacOSX12.3.sdk.tar.xz
MACOS_SDK_CHECKSUM: 3abd261ceb483c44295a6623fdffe5d44fc4ac2c872526576ec5ab5ad0f6e26c
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release
workdir: ./examples/tokenvm/
env:
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Archive Builds
uses: actions/upload-artifact@v3
with:
name: dist
path: ./examples/tokenvm/dist
main-release:
# We build with 20.04 to maintain max compatibility: https://github.com/golang/go/issues/57328
runs-on: ubuntu-20.04-32
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.event.ref, 'refs/tags/v')}}
steps:
- name: Git checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -56,7 +103,6 @@ jobs:
with:
name: dist
path: ./examples/tokenvm/dist


concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tokenvm-static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
Lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 30
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
28 changes: 24 additions & 4 deletions .github/workflows/tokenvm-sync-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,31 @@ on:
pull_request:

jobs:
tests:
cond-tests:
environment: 'long-ci'
if: ${{ github.ref != 'refs/heads/main'}}
runs-on:
labels: ubuntu-latest-16-cores
timeout-minutes: 45
labels: ubuntu-20.04-32
timeout-minutes: 25
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.20"
check-latest: true
- name: Run sync tests
working-directory: ./examples/tokenvm
shell: bash
run: scripts/run.sh
env:
MODE: "full-test"
main-tests:
if: ${{ github.ref == 'refs/heads/main'}}
runs-on:
labels: ubuntu-20.04-32
timeout-minutes: 25
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -28,7 +49,6 @@ jobs:
run: scripts/run.sh
env:
MODE: "full-test"

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
4 changes: 2 additions & 2 deletions .github/workflows/tokenvm-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ on:
jobs:
tests:
runs-on:
labels: ubuntu-latest-16-cores
timeout-minutes: 30
labels: ubuntu-20.04-32
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
tests:
name: Unit Tests
runs-on: ubuntu-latest
timeout-minutes: 30
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<a href="https://goreportcard.com/report/github.com/ava-labs/hypersdk"><img src="https://goreportcard.com/badge/github.com/ava-labs/hypersdk" /></a>
<a href="https://github.com/ava-labs/hypersdk/actions/workflows/unit-tests.yml"><img src="https://github.com/ava-labs/hypersdk/actions/workflows/unit-tests.yml/badge.svg" /></a>
<a href="https://github.com/ava-labs/hypersdk/actions/workflows/static-analysis.yml"><img src="https://github.com/ava-labs/hypersdk/actions/workflows/static-analysis.yml/badge.svg" /></a>
<a href="./LICENSE" ><img src="https://img.shields.io/badge/License-Ecosystem-blue.svg" /></a>
</p>

---
Expand Down
4 changes: 3 additions & 1 deletion chain/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,13 @@ func (b *StatelessBlock) innerVerify(ctx context.Context) (merkledb.TrieView, er
processor.Prefetch(ctx, state)

// Process new transactions
unitsConsumed, surplusFee, results, err := processor.Execute(ctx, ectx, r)
unitsConsumed, surplusFee, results, stateChanges, stateOps, err := processor.Execute(ctx, ectx, r)
if err != nil {
log.Error("failed to execute block", zap.Error(err))
return nil, err
}
b.vm.RecordStateChanges(stateChanges)
b.vm.RecordStateOperations(stateOps)
b.results = results
if b.UnitsConsumed != unitsConsumed {
return nil, fmt.Errorf(
Expand Down
10 changes: 7 additions & 3 deletions chain/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/ava-labs/avalanchego/ids"
smblock "github.com/ava-labs/avalanchego/snow/engine/snowman/block"
"github.com/ava-labs/avalanchego/utils/math"
"go.opentelemetry.io/otel/attribute"
"go.uber.org/zap"

Expand Down Expand Up @@ -66,12 +67,13 @@ func BuildBlock(
}
b := NewBlock(ectx, vm, parent, nextTime)

state, err := parent.childState(ctx, r.GetMaxBlockTxs())
changesEstimate := math.Min(vm.Mempool().Len(ctx), r.GetMaxBlockTxs())
state, err := parent.childState(ctx, changesEstimate)
if err != nil {
log.Warn("block building failed: couldn't get parent db", zap.Error(err))
return nil, err
}
ts := tstate.New(r.GetMaxBlockTxs(), r.GetMaxBlockTxs())
ts := tstate.New(changesEstimate)

// Restorable txs after block attempt finishes
b.Txs = []*Transaction{}
Expand Down Expand Up @@ -155,7 +157,7 @@ func BuildBlock(
// TODO: prefetch state of upcoming txs that we will pull (should make much
// faster)
txStart := ts.OpIndex()
if err := ts.FetchAndSetScope(ctx, state, next.StateKeys(sm)); err != nil {
if err := ts.FetchAndSetScope(ctx, next.StateKeys(sm), state); err != nil {
return false, true, false, err
}

Expand Down Expand Up @@ -280,6 +282,8 @@ func BuildBlock(
zap.Int("mempool size", b.vm.Mempool().Len(ctx)),
zap.Duration("mempool lock wait", lockWait),
zap.Bool("context", blockContext != nil),
zap.Int("state changes", ts.PendingChanges()),
zap.Int("state operations", ts.OpIndex()),
)
return b, nil
}
11 changes: 6 additions & 5 deletions chain/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ type VM interface {
UpdateSyncTarget(*StatelessBlock) (bool, error)
StateReady() bool

// Record the duration of various operations to populate chain metrics
// Collect useful metrics
//
// If there was a long-lived [Chain] struct, we would store metrics for chain
// there.
RecordRootCalculated(t time.Duration) // only called in Verify
RecordWaitSignatures(t time.Duration) // only called in Verify
// TODO: break out into own interface
RecordRootCalculated(time.Duration) // only called in Verify
RecordWaitSignatures(time.Duration) // only called in Verify
RecordStateChanges(int)
RecordStateOperations(int)
}

type Mempool interface {
Expand Down
Loading

0 comments on commit 697b3e3

Please sign in to comment.