Skip to content

Commit

Permalink
fix tokenvm
Browse files Browse the repository at this point in the history
  • Loading branch information
wlawt committed Apr 23, 2024
1 parent 1cb8180 commit a628986
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 148 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")
)
15 changes: 7 additions & 8 deletions examples/tokenvm/cmd/token-cli/cmd/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package cmd

import (
"context"
"errors"
"time"

"github.com/ava-labs/avalanchego/ids"
Expand Down Expand Up @@ -76,7 +75,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 +125,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 +168,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 +232,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 +269,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 +355,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 +472,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
12 changes: 6 additions & 6 deletions examples/tokenvm/cmd/token-cli/cmd/resolutions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion examples/tokenvm/cmd/token-cli/cmd/spam.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ var runSpamCmd = &cobra.Command{
},
func(cli *rpc.JSONRPCClient, priv *cli.PrivateKey) func(context.Context, uint64) error { // submitDummy
return func(ictx context.Context, count uint64) error {
_, _, err := sendAndWait(ictx, nil, &actions.Transfer{
_, _, err := sendAndWait(ictx, &actions.Transfer{
To: priv.Address,
Value: count, // prevent duplicate txs
}, cli, sclient, tclient, auth.NewED25519Factory(ed25519.PrivateKey(priv.Bytes)), false)
Expand Down
2 changes: 1 addition & 1 deletion examples/tokenvm/cmd/token-faucet/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (m *Manager) sendFunds(ctx context.Context, destination codec.Address, amou
if err != nil {
return ids.Empty, 0, err
}
submit, tx, maxFee, err := m.cli.GenerateTransaction(ctx, parser, nil, &actions.Transfer{
submit, tx, maxFee, err := m.cli.GenerateTransaction(ctx, parser, &actions.Transfer{
To: destination,
Asset: ids.Empty,
Value: amount,
Expand Down
Loading

0 comments on commit a628986

Please sign in to comment.