Skip to content

Commit

Permalink
fix tokenvm
Browse files Browse the repository at this point in the history
  • Loading branch information
wlawt committed Apr 24, 2024
1 parent 1cb8180 commit e8e6b68
Show file tree
Hide file tree
Showing 20 changed files with 114 additions and 162 deletions.
6 changes: 3 additions & 3 deletions chain/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type StatefulBlock struct {
// or [Verify], which reduces the amount of time we are
// blocking the consensus engine from voting on the block,
// starting the verification of another block, etc.
StateRoot ids.ID `json:"stateRoot"`
StateRoot ids.ID `json:"stateRoot"`

size int

Expand Down Expand Up @@ -100,8 +100,8 @@ type StatelessBlock struct {
bytes []byte
txsSet set.Set[ids.ID]

bctx *block.Context
vdrState validators.State
bctx *block.Context
vdrState validators.State

Check failure on line 104 in chain/block.go

View workflow job for this annotation

GitHub Actions / hypersdk-lint

field `vdrState` is unused (unused)

results []*Result
feeManager *fees.Manager
Expand Down
2 changes: 1 addition & 1 deletion chain/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func BuildBlock(
txsAttempted = 0
results = []*Result{}

sm = vm.StateManager()
sm = vm.StateManager()

// prepareStreamLock ensures we don't overwrite stream prefetching spawned
// asynchronously.
Expand Down
8 changes: 4 additions & 4 deletions chain/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ const (
// This value should be (much) less than the value of [ProposerWindow], otherwise honest
// nodes may not build during their allocated window to avoid increasing the skew of the
// chain time.
FutureBound = 1 * time.Second
HeightKeyChunks = 1
TimestampKeyChunks = 1
FeeKeyChunks = 8 // 96 (per dimension) * 5 (num dimensions)
FutureBound = 1 * time.Second
HeightKeyChunks = 1
TimestampKeyChunks = 1
FeeKeyChunks = 8 // 96 (per dimension) * 5 (num dimensions)

// MaxKeyDependencies must be greater than the maximum number of key dependencies
// any single task could have when executing a task.
Expand Down
14 changes: 7 additions & 7 deletions chain/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ var (
)

type Transaction struct {
Base *Base `json:"base"`
Base *Base `json:"base"`

// TODO: turn [Action] into an array (#335)
Action Action `json:"action"`
Auth Auth `json:"auth"`

digest []byte
bytes []byte
size int
id ids.ID
digest []byte
bytes []byte
size int
id ids.ID
stateKeys state.Keys
}

func NewTx(base *Base, act Action) *Transaction {
return &Transaction{
Base: base,
Action: act,
Base: base,
Action: act,
}
}

Expand Down
8 changes: 4 additions & 4 deletions cli/spam.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (h *Handler) Spam(
return err
}
action := getTransfer(keys[0].Address, 0)
maxUnits, err := chain.EstimateMaxUnits(parser.Rules(time.Now().UnixMilli()), action, factory, nil)
maxUnits, err := chain.EstimateMaxUnits(parser.Rules(time.Now().UnixMilli()), action, factory)
if err != nil {
return err
}
Expand Down Expand Up @@ -167,7 +167,7 @@ func (h *Handler) Spam(
accounts[i] = pk

// Send funds
_, tx, err := cli.GenerateTransactionManual(parser, nil, getTransfer(pk.Address, distAmount), factory, feePerTx)
_, tx, err := cli.GenerateTransactionManual(parser, getTransfer(pk.Address, distAmount), factory, feePerTx)
if err != nil {
return err
}
Expand Down Expand Up @@ -316,7 +316,7 @@ func (h *Handler) Spam(
if maxFee != nil {
fee = *maxFee
}
_, tx, err := issuer.c.GenerateTransactionManual(parser, nil, action, factory, fee, tm)
_, tx, err := issuer.c.GenerateTransactionManual(parser, action, factory, fee, tm)
if err != nil {
utils.Outf("{{orange}}failed to generate tx:{{/}} %v\n", err)
continue
Expand Down Expand Up @@ -424,7 +424,7 @@ func (h *Handler) Spam(
if err != nil {
return err
}
_, tx, err := cli.GenerateTransactionManual(parser, nil, getTransfer(key.Address, returnAmt), f, feePerTx)
_, tx, err := cli.GenerateTransactionManual(parser, getTransfer(key.Address, returnAmt), f, feePerTx)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion examples/morpheusvm/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func Default() *Genesis {
ValidityWindow: 60 * hconsts.MillisecondsPerSecond, // ms

// Tx Fee Compute Parameters
BaseComputeUnits: 1,
BaseComputeUnits: 1,

// Tx Fee Storage Parameters
//
Expand Down
8 changes: 4 additions & 4 deletions examples/morpheusvm/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ const (
txPrefix = 0x0

// stateDB
balancePrefix = 0x0
heightPrefix = 0x1
timestampPrefix = 0x2
feePrefix = 0x3
balancePrefix = 0x0
heightPrefix = 0x1
timestampPrefix = 0x2
feePrefix = 0x3
)

const BalanceChunks uint16 = 1
Expand Down
58 changes: 29 additions & 29 deletions examples/tokenvm/actions/outputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@
package actions

var (
OutputValueZero = []byte("value is zero")
OutputMemoTooLarge = []byte("memo is too large")
OutputAssetIsNative = []byte("cannot mint native asset")
OutputAssetAlreadyExists = []byte("asset already exists")
OutputAssetMissing = []byte("asset missing")
OutputInTickZero = []byte("in rate is zero")
OutputOutTickZero = []byte("out rate is zero")
OutputSupplyZero = []byte("supply is zero")
OutputSupplyMisaligned = []byte("supply is misaligned")
OutputOrderMissing = []byte("order is missing")
OutputUnauthorized = []byte("unauthorized")
OutputWrongIn = []byte("wrong in asset")
OutputWrongOut = []byte("wrong out asset")
OutputWrongOwner = []byte("wrong owner")
OutputInsufficientInput = []byte("insufficient input")
OutputInsufficientOutput = []byte("insufficient output")
OutputValueMisaligned = []byte("value is misaligned")
OutputSymbolEmpty = []byte("symbol is empty")
OutputSymbolIncorrect = []byte("symbol is incorrect")
OutputSymbolTooLarge = []byte("symbol is too large")
OutputDecimalsIncorrect = []byte("decimal is incorrect")
OutputDecimalsTooLarge = []byte("decimal is too large")
OutputMetadataEmpty = []byte("metadata is empty")
OutputMetadataTooLarge = []byte("metadata is too large")
OutputSameInOut = []byte("same asset used for in and out")
OutputAnycast = []byte("anycast output")
OutputWrongDestination = []byte("wrong destination")
OutputMustFill = []byte("must fill request")
OutputInvalidDestination = []byte("invalid destination")
OutputValueZero = []byte("value is zero")
OutputMemoTooLarge = []byte("memo is too large")
OutputAssetIsNative = []byte("cannot mint native asset")
OutputAssetAlreadyExists = []byte("asset already exists")
OutputAssetMissing = []byte("asset missing")
OutputInTickZero = []byte("in rate is zero")
OutputOutTickZero = []byte("out rate is zero")
OutputSupplyZero = []byte("supply is zero")
OutputSupplyMisaligned = []byte("supply is misaligned")
OutputOrderMissing = []byte("order is missing")
OutputUnauthorized = []byte("unauthorized")
OutputWrongIn = []byte("wrong in asset")
OutputWrongOut = []byte("wrong out asset")
OutputWrongOwner = []byte("wrong owner")
OutputInsufficientInput = []byte("insufficient input")
OutputInsufficientOutput = []byte("insufficient output")
OutputValueMisaligned = []byte("value is misaligned")
OutputSymbolEmpty = []byte("symbol is empty")
OutputSymbolIncorrect = []byte("symbol is incorrect")
OutputSymbolTooLarge = []byte("symbol is too large")
OutputDecimalsIncorrect = []byte("decimal is incorrect")
OutputDecimalsTooLarge = []byte("decimal is too large")
OutputMetadataEmpty = []byte("metadata is empty")
OutputMetadataTooLarge = []byte("metadata is too large")
OutputSameInOut = []byte("same asset used for in and out")
OutputAnycast = []byte("anycast output")
OutputWrongDestination = []byte("wrong destination")
OutputMustFill = []byte("must fill request")
OutputInvalidDestination = []byte("invalid destination")
)
21 changes: 7 additions & 14 deletions examples/tokenvm/cmd/token-cli/cmd/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,13 @@ package cmd

import (
"context"
"errors"
"time"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/hypersdk/chain"
"github.com/ava-labs/hypersdk/codec"
"github.com/ava-labs/hypersdk/consts"
"github.com/ava-labs/hypersdk/examples/tokenvm/actions"
frpc "github.com/ava-labs/hypersdk/examples/tokenvm/cmd/token-faucet/rpc"
tconsts "github.com/ava-labs/hypersdk/examples/tokenvm/consts"
trpc "github.com/ava-labs/hypersdk/examples/tokenvm/rpc"
"github.com/ava-labs/hypersdk/pubsub"
"github.com/ava-labs/hypersdk/rpc"
hutils "github.com/ava-labs/hypersdk/utils"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -76,7 +69,7 @@ var fundFaucetCmd = &cobra.Command{
if err != nil {
return err
}
if _, _, err = sendAndWait(ctx, nil, &actions.Transfer{
if _, _, err = sendAndWait(ctx, &actions.Transfer{
To: addr,
Asset: ids.Empty,
Value: amount,
Expand Down Expand Up @@ -126,7 +119,7 @@ var transferCmd = &cobra.Command{
}

// Generate transaction
_, _, err = sendAndWait(ctx, nil, &actions.Transfer{
_, _, err = sendAndWait(ctx, &actions.Transfer{
To: recipient,
Asset: assetID,
Value: amount,
Expand Down Expand Up @@ -169,7 +162,7 @@ var createAssetCmd = &cobra.Command{
}

// Generate transaction
_, _, err = sendAndWait(ctx, nil, &actions.CreateAsset{
_, _, err = sendAndWait(ctx, &actions.CreateAsset{
Symbol: []byte(symbol),
Decimals: uint8(decimals), // already constrain above to prevent overflow
Metadata: []byte(metadata),
Expand Down Expand Up @@ -233,7 +226,7 @@ var mintAssetCmd = &cobra.Command{
}

// Generate transaction
_, _, err = sendAndWait(ctx, nil, &actions.MintAsset{
_, _, err = sendAndWait(ctx, &actions.MintAsset{
Asset: assetID,
To: recipient,
Value: amount,
Expand Down Expand Up @@ -270,7 +263,7 @@ var closeOrderCmd = &cobra.Command{
}

// Generate transaction
_, _, err = sendAndWait(ctx, nil, &actions.CloseOrder{
_, _, err = sendAndWait(ctx, &actions.CloseOrder{
Order: orderID,
Out: outAssetID,
}, cli, scli, tcli, factory, true)
Expand Down Expand Up @@ -356,7 +349,7 @@ var createOrderCmd = &cobra.Command{
}

// Generate transaction
_, _, err = sendAndWait(ctx, nil, &actions.CreateOrder{
_, _, err = sendAndWait(ctx, &actions.CreateOrder{
In: inAssetID,
InTick: inTick,
Out: outAssetID,
Expand Down Expand Up @@ -473,7 +466,7 @@ var fillOrderCmd = &cobra.Command{
if err != nil {
return err
}
_, _, err = sendAndWait(ctx, nil, &actions.FillOrder{
_, _, err = sendAndWait(ctx, &actions.FillOrder{
Order: order.ID,
Owner: owner,
In: inAssetID,
Expand Down
1 change: 0 additions & 1 deletion examples/tokenvm/cmd/token-cli/cmd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/ava-labs/hypersdk/chain"
"github.com/ava-labs/hypersdk/cli"
"github.com/ava-labs/hypersdk/codec"
hconsts "github.com/ava-labs/hypersdk/consts"
"github.com/ava-labs/hypersdk/crypto/ed25519"
"github.com/ava-labs/hypersdk/examples/tokenvm/auth"
"github.com/ava-labs/hypersdk/examples/tokenvm/consts"
Expand Down
26 changes: 13 additions & 13 deletions examples/tokenvm/cmd/token-cli/cmd/resolutions.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ import (
func sendAndWait(
ctx context.Context, action chain.Action, cli *rpc.JSONRPCClient,
scli *rpc.WebSocketClient, tcli *trpc.JSONRPCClient, factory chain.AuthFactory, printStatus bool,
) (bool, ids.ID, error) {
) (ids.ID, error) {
parser, err := tcli.Parser(ctx)
if err != nil {
return false, ids.Empty, err
return ids.Empty, err
}
_, tx, _, err := cli.GenerateTransaction(ctx, parser, action, factory)
if err != nil {
return false, ids.Empty, err
return ids.Empty, err
}

if err := scli.RegisterTx(tx); err != nil {
return false, ids.Empty, err
return ids.Empty, err
}
var res *chain.Result
for {
txID, dErr, result, err := scli.ListenTx(ctx)
if dErr != nil {
return false, ids.Empty, dErr
return ids.Empty, dErr
}
if err != nil {
return false, ids.Empty, err
return ids.Empty, err
}
if txID == tx.ID() {
res = result
Expand All @@ -54,7 +54,7 @@ func sendAndWait(
if printStatus {
handler.Root().PrintStatus(tx.ID(), res.Success)
}
return res.Success, tx.ID(), nil
return tx.ID(), nil
}

func handleTx(c *trpc.JSONRPCClient, tx *chain.Transaction, result *chain.Result) {
Expand All @@ -67,7 +67,7 @@ func handleTx(c *trpc.JSONRPCClient, tx *chain.Transaction, result *chain.Result
case *actions.CreateAsset:
summaryStr = fmt.Sprintf("assetID: %s symbol: %s decimals: %d metadata: %s", tx.ID(), action.Symbol, action.Decimals, action.Metadata)
case *actions.MintAsset:
_, symbol, decimals, _, _, _, _, err := c.Asset(context.TODO(), action.Asset, true)
_, symbol, decimals, _, _, _, err := c.Asset(context.TODO(), action.Asset, true)
if err != nil {
utils.Outf("{{red}}could not fetch asset info:{{/}} %v", err)
return
Expand All @@ -78,7 +78,7 @@ func handleTx(c *trpc.JSONRPCClient, tx *chain.Transaction, result *chain.Result
summaryStr = fmt.Sprintf("%d %s -> 🔥", action.Value, action.Asset)

case *actions.Transfer:
_, symbol, decimals, _, _, _, _, err := c.Asset(context.TODO(), action.Asset, true)
_, symbol, decimals, _, _, _, err := c.Asset(context.TODO(), action.Asset, true)
if err != nil {
utils.Outf("{{red}}could not fetch asset info:{{/}} %v", err)
return
Expand All @@ -90,13 +90,13 @@ func handleTx(c *trpc.JSONRPCClient, tx *chain.Transaction, result *chain.Result
}

case *actions.CreateOrder:
_, inSymbol, inDecimals, _, _, _, _, err := c.Asset(context.TODO(), action.In, true)
_, inSymbol, inDecimals, _, _, _, err := c.Asset(context.TODO(), action.In, true)
if err != nil {
utils.Outf("{{red}}could not fetch asset info:{{/}} %v", err)
return
}
inTickStr := utils.FormatBalance(action.InTick, inDecimals)
_, outSymbol, outDecimals, _, _, _, _, err := c.Asset(context.TODO(), action.Out, true)
_, outSymbol, outDecimals, _, _, _, err := c.Asset(context.TODO(), action.Out, true)
if err != nil {
utils.Outf("{{red}}could not fetch asset info:{{/}} %v", err)
return
Expand All @@ -106,13 +106,13 @@ func handleTx(c *trpc.JSONRPCClient, tx *chain.Transaction, result *chain.Result
summaryStr = fmt.Sprintf("%s %s -> %s %s (supply: %s %s)", inTickStr, inSymbol, outTickStr, outSymbol, supplyStr, outSymbol)
case *actions.FillOrder:
or, _ := actions.UnmarshalOrderResult(result.Output)
_, inSymbol, inDecimals, _, _, _, _, err := c.Asset(context.TODO(), action.In, true)
_, inSymbol, inDecimals, _, _, _, err := c.Asset(context.TODO(), action.In, true)
if err != nil {
utils.Outf("{{red}}could not fetch asset info:{{/}} %v", err)
return
}
inAmtStr := utils.FormatBalance(or.In, inDecimals)
_, outSymbol, outDecimals, _, _, _, _, err := c.Asset(context.TODO(), action.Out, true)
_, outSymbol, outDecimals, _, _, _, err := c.Asset(context.TODO(), action.Out, true)
if err != nil {
utils.Outf("{{red}}could not fetch asset info:{{/}} %v", err)
return
Expand Down
3 changes: 0 additions & 3 deletions examples/tokenvm/cmd/token-cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@ func init() {
createOrderCmd,
fillOrderCmd,
closeOrderCmd,

importAssetCmd,
exportAssetCmd,
)

// spam
Expand Down
Loading

0 comments on commit e8e6b68

Please sign in to comment.