From 2b251e6fe1114cf6b65c46ce53a9280be61d4ffc Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Tue, 18 Jan 2022 21:17:55 -0800 Subject: [PATCH 01/15] readme progress --- README.md | 365 +++++++++++++++++------------------------------------- 1 file changed, 115 insertions(+), 250 deletions(-) diff --git a/README.md b/README.md index 8875a488..b4cd57d6 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,67 @@ -# SpacesVM +# SpacesVM -Avalanche is a network composed of multiple blockchains. Each blockchain is an instance of a [Virtual Machine (VM)](https://docs.avax.network/learn/platform-overview#virtual-machines), much like an object in an object-oriented language is an instance of a class. That is, the VM defines the behavior of the blockchain. +Avalanche is a network composed of multiple blockchains. Each blockchain is an instance +of a [Virtual Machine (VM)](https://docs.avax.network/learn/platform-overview#virtual-machines), +much like an object in an object-oriented language is an instance of a class. That is, +the VM defines the behavior of the blockchain where it is instantiated. The use of +[Coreth (EVM)](https://github.com/ava-labs/coreth) on the [Avalanche C-Chain](https://docs.avax.network/learn/platform-overview) +is a canonical use case of a virtual machine (EVM) and its instantiation (C-Chain) on the Primary Subnet (Avalanche Mainnet). One +could deploy their own instance of the EVM as their own blockchain (to take +this to its logical conclusion. -EVM on Avalanche is a canonical use case of virtual machine (VM) that enables smart contracts for decentralized finance applications. KVVM extends beyond smart contracts platform, to provide the key-value storage engine for an ever-growing number of diverse applications, powered by Avalanche protocol. +Just as Coreth powers the C-Chain, SpacesVM can be used to power its own +blockchain. However, instead of providing a place to execute smart contracts on +decentralized applications, SpacesVM enables anyone to store arbitrary data for +fast retrieval, like a Key-Value Database where a single party controls an +entire hierarchy of keys, you can claim your own hierarchy. (TODO). -KVVM defines a blockchain that is a key-value storage server. Each block in the blockchain contains a set of key-value pairs. This VM demonstrates capabilities of custom VMs and custom blockchains. For more information, see: [Create a Virtual Machine](https://docs.avax.network/build/tutorials/platform/create-a-virtual-machine-vm) +You could build... +* Name Service +* Link Service +* dApp Metadata Backend +* Twitter Feed-like -KVVM is served over RPC with [go-plugin](https://github.com/hashicorp/go-plugin). +## +More complex example than timestampvm but simpler than subnet-evm -# spacesvm -To build the VM, run `VM=true ./scripts/build.sh`. +## How it Works +### Claim + +### Set/Delete + +#### Arbitrary Size File Support (using CLI) + +### Resolve + +### Transfer + +### Move + +## Wallet Support: `eth_typedSignedData` +TODO: Insert image of signing using MM + +## Fee Mechanisms +Claim Desirability + Decay Rate +FeeUnits vs Load Units +Expiry Rate vs Units + +## Space Rewards +Lottery allocation X% of fee + +### Genesis Allocation +Airdrop `10,000 SPC` for anyone who has interacted with C-Chain more than +twice. + +## Usage +_If you are interested in running the VM, not using it. Jump to [Running the +VM](#running-the-vm)._ -# spaces-cli +### Public Beta +What better way to understand how this works than to see it in action? + +TODO: insert try spaces image + link + +### spaces-cli _To build the CLI, run `./scripts/build.sh`. It will be placed in `./build/spaces-cli` and `$GOBIN/spaces-cli`._ @@ -47,9 +97,16 @@ Flags: Use "spaces-cli [command] --help" for more information about a command. ``` -# Public Endpoints (`/public`) +#### Uploading Files +``` +spaces-cli set-file patrick ~/Downloads/computer.gif -> patrick/6fe5a52f52b34fb1e07ba90bad47811c645176d0d49ef0c7a7b4b22013f676c8 +spaces-cli resolve-file patrick/6fe5a52f52b34fb1e07ba90bad47811c645176d0d49ef0c7a7b4b22013f676c8 computer_copy.gif +spaces-cli delete-file patrick/6fe5a52f52b34fb1e07ba90bad47811c645176d0d49ef0c7a7b4b22013f676c8 +``` + +### Public Endpoints (`/public`) -## spacesvm.ping +#### spacesvm.ping ``` <<< POST { @@ -61,7 +118,7 @@ Use "spaces-cli [command] --help" for more information about a command. >>> {"sucess":} ``` -## spacesvm.genesis +#### spacesvm.genesis ``` <<< POST { @@ -73,7 +130,7 @@ Use "spaces-cli [command] --help" for more information about a command. >>> {"genesis":} ``` -## spacesvm.suggestedFee +#### spacesvm.suggestedFee _Provide your intent and get back a transaction to sign._ ``` <<< POST @@ -89,7 +146,7 @@ _Provide your intent and get back a transaction to sign._ >>> "totalCost":} ``` -### chain.Input +##### chain.Input ``` { "type":, @@ -101,7 +158,7 @@ _Provide your intent and get back a transaction to sign._ } ``` -#### Transaction Types +###### Transaction Types ``` claim {type,space} lifeline {type,space,units} @@ -112,7 +169,7 @@ transfer {type,to,units} ``` -## spacesvm.issueTx +#### spacesvm.issueTx ``` <<< POST { @@ -127,7 +184,16 @@ transfer {type,to,units} >>> {"txId":} ``` -## spacesvm.hasTx +##### Transaction Creation Worflow +``` +1) spacesvm.claimed {"space":"patrick"} => Yes/No +2) spacesvm.suggestedFee {"input":{"type":"claim", "space":"patrick"}} => {"typedData":, "cost":} +3) sign EIP-712 Typed Data +4) spacesvm.issueTx {"typedData":, "signature":} => {"txId":} +5) [loop] spacesvm.hasTx {"txId":} => {"accepted":true"} +``` + +#### spacesvm.hasTx ``` <<< POST { @@ -141,7 +207,7 @@ transfer {type,to,units} >>> {"accepted":} ``` -## spacesvm.lastAccepted +#### spacesvm.lastAccepted ``` <<< POST { @@ -153,7 +219,7 @@ transfer {type,to,units} >>> {"height":, "blockId":} ``` -## spacesvm.claimed +#### spacesvm.claimed ``` <<< POST { @@ -167,7 +233,7 @@ transfer {type,to,units} >>> {"claimed":} ``` -## spacesvm.info +#### spacesvm.info ``` <<< POST { @@ -181,7 +247,7 @@ transfer {type,to,units} >>> {"info":, "values":[]} ``` -### chain.SpaceInfo +##### chain.SpaceInfo ``` { "owner":, @@ -193,7 +259,7 @@ transfer {type,to,units} } ``` -### chain.KeyValueMeta +##### chain.KeyValueMeta ``` { "key":, @@ -206,7 +272,7 @@ transfer {type,to,units} } ``` -## spacesvm.resolve +#### spacesvm.resolve ``` <<< POST { @@ -220,7 +286,7 @@ transfer {type,to,units} >>> {"exists":, "value":, "valueMeta":} ``` -## spacesvm.balance +#### spacesvm.balance ``` <<< POST { @@ -234,7 +300,7 @@ transfer {type,to,units} >>> {"balance":} ``` -## spacesvm.recentActivity +#### spacesvm.recentActivity ``` <<< POST { @@ -246,7 +312,7 @@ transfer {type,to,units} >>> {"activity":[,...]} ``` -### chain.Activity +##### chain.Activity ``` { "timestamp":, @@ -260,7 +326,7 @@ transfer {type,to,units} } ``` -#### Activity Types +###### Activity Types ``` claim {timestamp,sender,txId,type,space} lifeline {timestamp,sender,txId,type,space,units} @@ -271,9 +337,9 @@ transfer {timestamp,sender,txId,type,to,units} reward {timestamp,txId,type,to,units} ``` -# Advanced Public Endpoints (`/public`) +### Advanced Public Endpoints (`/public`) -## spacesvm.suggestedRawFee +#### spacesvm.suggestedRawFee _Can use this to get the current fee rate._ ``` <<< POST @@ -286,7 +352,7 @@ _Can use this to get the current fee rate._ >>> {"price":,"cost":} ``` -## spacesvm.issueRawTx +#### spacesvm.issueRawTx ``` <<< POST { @@ -300,64 +366,42 @@ _Can use this to get the current fee rate._ >>> {"txId":} ``` -# Creating Transactions -``` -1) spacesvm.claimed {"space":"patrick"} => Yes/No -2) spacesvm.suggestedFee {"input":{"type":"claim", "space":"patrick"}} => {"typedData":, "cost":} -3) sign EIP-712 Typed Data -4) spacesvm.issueTx {"typedData":, "signature":} => {"txId":} -5) [loop] spacesvm.hasTx {"txId":} => {"accepted":true"} -``` - -# Uploading Files -``` -spaces-cli set-file patrick ~/Downloads/computer.gif -> patrick/6fe5a52f52b34fb1e07ba90bad47811c645176d0d49ef0c7a7b4b22013f676c8 -spaces-cli resolve-file patrick/6fe5a52f52b34fb1e07ba90bad47811c645176d0d49ef0c7a7b4b22013f676c8 computer_copy.gif -spaces-cli delete-file patrick/6fe5a52f52b34fb1e07ba90bad47811c645176d0d49ef0c7a7b4b22013f676c8 -``` - -////// REWRITE /////////////// -# Features -TODO: Extend on -* PoW Transactions (no tokens) -* No Nonces (replay protection from blockId + txId) -* Prefixes (address prefixes reserved) -* Hashed Value Keys -* Prefix Expiry (based on weight of all key-values) -* Load Units vs Fee Units -* Lifeline Rewards (why run a node -> don't need to mine) -* Block Value Reuse - -# RPC -## /public -* range query +## Running the VM +To build the VM, run `VM=true ./scripts/build.sh`. -## /private -* set beneficiary +### Joining the public beta +Put spacesvm binary in plugins dir +Add subnet-id to whitelisted-subnets -# Quick start +Here is an example config file: +--network-id=fuji -At its core, the Avalanche protocol still maintains the immutable ordered sequence of states in a fully permissionless settings. And KVVM defines the rules and data structures to store key-value pairs. +Make sure to add these commands when running the node: +--config-file -## Run `spacesvm` with local network +If you'd like to become a validator, reach out to @\_patrickogrady on Twitter +after you've joined the network and synced to tip. Please send a screenshot +indicating you've done this successfully. -[`scripts/run.sh`](scripts/run.sh) automatically installs [avalanchego](https://github.com/ava-labs/avalanchego) to set up a local networkand creates a `spacesvm` genesis file. To build and run E2E tests, you need to set the variable `E2E` before it: `E2E=true ./scripts/run.sh 1.7.3` +### Running a local network +[`scripts/run.sh`](scripts/run.sh) automatically installs [avalanchego](https://github.com/ava-labs/avalanchego) to set up a local network +and creates a `spacesvm` genesis file. To build and run E2E tests, you need to set the variable `E2E` before it: `E2E=true ./scripts/run.sh 1.7.4` See [`tests/e2e`](tests/e2e) and [`tests/runner`](tests/runner) to see how it's set up and how its client requests are made: ```bash # to startup a cluster cd ${HOME}/go/src/github.com/ava-labs/spacesvm -./scripts/run.sh 1.7.3 +./scripts/run.sh 1.7.4 # to run full e2e tests and shut down cluster afterwards cd ${HOME}/go/src/github.com/ava-labs/spacesvm -E2E=true ./scripts/run.sh 1.7.3 +E2E=true ./scripts/run.sh 1.7.4 ``` ```bash # inspect cluster endpoints when ready -cat /tmp/avalanchego-v1.7.3/output.yaml +cat /tmp/avalanchego-v1.7.4/output.yaml < Date: Tue, 18 Jan 2022 21:52:01 -0800 Subject: [PATCH 02/15] cleanup CLI --- README.md | 45 +++++++++++++++++++++++ chain/lifeline_tx.go | 8 ++--- chain/storage.go | 1 - client/helper.go | 60 +++++++++++++++++-------------- cmd/spacescli/cmd/activity.go | 1 - cmd/spacescli/cmd/claim.go | 48 ++++++++----------------- cmd/spacescli/cmd/common.go | 2 +- cmd/spacescli/cmd/delete-file.go | 9 +++-- cmd/spacescli/cmd/delete.go | 21 +++++------ cmd/spacescli/cmd/genesis.go | 2 +- cmd/spacescli/cmd/info.go | 1 - cmd/spacescli/cmd/lifeline.go | 23 ++++++------ cmd/spacescli/cmd/move.go | 15 ++++---- cmd/spacescli/cmd/resolve-file.go | 9 +++-- cmd/spacescli/cmd/resolve.go | 2 +- cmd/spacescli/cmd/root.go | 9 ++++- cmd/spacescli/cmd/set-file.go | 11 ++---- cmd/spacescli/cmd/set.go | 51 ++++++++++---------------- cmd/spacescli/cmd/transfer.go | 15 +++----- tree/tree.go | 8 ++--- 20 files changed, 177 insertions(+), 164 deletions(-) diff --git a/README.md b/README.md index b4cd57d6..4388d697 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,8 @@ More complex example than timestampvm but simpler than subnet-evm ## How it Works ### Claim +#### Community support + ### Set/Delete #### Arbitrary Size File Support (using CLI) @@ -104,6 +106,49 @@ spaces-cli resolve-file patrick/6fe5a52f52b34fb1e07ba90bad47811c645176d0d49ef0c7 spaces-cli delete-file patrick/6fe5a52f52b34fb1e07ba90bad47811c645176d0d49ef0c7a7b4b22013f676c8 ``` +### Golang SDK +TODO: add link +```golang +// Client defines spacesvm client operations. +type Client interface { + // Pings the VM. + Ping() (bool, error) + + // Returns the VM genesis. + Genesis() (*chain.Genesis, error) + // Accepted fetches the ID of the last accepted block. + Accepted() (ids.ID, error) + + // Returns if a space is already claimed + Claimed(space string) (bool, error) + // Returns the corresponding space information. + Info(space string) (*chain.SpaceInfo, []*chain.KeyValueMeta, error) + // Balance returns the balance of an account + Balance(addr common.Address) (bal uint64, err error) + // Resolve returns the value associated with a path + Resolve(path string) (exists bool, value []byte, valueMeta *chain.ValueMeta, err error) + + // Requests the suggested price and cost from VM. + SuggestedRawFee() (uint64, uint64, error) + // Issues the transaction and returns the transaction ID. + IssueRawTx(d []byte) (ids.ID, error) + + // Requests the suggested price and cost from VM, returns the input as + // TypedData. + SuggestedFee(i *chain.Input) (*tdata.TypedData, uint64, error) + // Issues a human-readable transaction and returns the transaction ID. + IssueTx(td *tdata.TypedData, sig []byte) (ids.ID, error) + + // Checks the status of the transaction, and returns "true" if confirmed. + HasTx(id ids.ID) (bool, error) + // Polls the transactions until its status is confirmed. + PollTx(ctx context.Context, txID ids.ID) (confirmed bool, err error) + + // Recent actions on the network (sorted from recent to oldest) + RecentActivity() ([]*chain.Activity, error) +} +``` + ### Public Endpoints (`/public`) #### spacesvm.ping diff --git a/chain/lifeline_tx.go b/chain/lifeline_tx.go index c1d04834..b182355f 100644 --- a/chain/lifeline_tx.go +++ b/chain/lifeline_tx.go @@ -15,15 +15,15 @@ var _ UnsignedTransaction = &LifelineTx{} type LifelineTx struct { *BaseTx `serialize:"true" json:"baseTx"` - // Space is the namespace for the "PrefixInfo" + // Space is the namespace for the "SpaceInfo" // whose owner can write and read value for the // specific key space. + // // The space must be ^[a-z0-9]{1,256}$. Space string `serialize:"true" json:"space"` - // Units is the additional fee the sender pays to extend the life of their - // space. The added expiry time is a function of: - // [Units] * [LifelineInterval]. + // Units is the number of [ClaimReward] to extend + // the life of the [Space]. Units uint64 `serialize:"true" json:"units"` } diff --git a/chain/storage.go b/chain/storage.go index 36a0e2db..77f663d5 100644 --- a/chain/storage.go +++ b/chain/storage.go @@ -22,7 +22,6 @@ import ( "github.com/ava-labs/spacesvm/parser" ) -// TODO: cleanup mapping diagram // 0x0/ (block hashes) // 0x1/ (tx hashes) // -> [tx hash]=>nil diff --git a/client/helper.go b/client/helper.go index 41cb0677..3cac41eb 100644 --- a/client/helper.go +++ b/client/helper.go @@ -11,6 +11,7 @@ import ( "time" "github.com/ava-labs/avalanchego/ids" + "github.com/ethereum/go-ethereum/crypto" "github.com/fatih/color" "github.com/ava-labs/spacesvm/chain" @@ -70,28 +71,9 @@ func SignIssueTx( return ids.Empty, 0, err } - if ret.pollTx { - color.Green("issued transaction %s (now polling)", txID) - confirmed, err := cli.PollTx(ctx, txID) - if err != nil { - return ids.Empty, 0, err - } - if !confirmed { - color.Yellow("transaction %s not confirmed", txID) - } else { - color.Green("transaction %s confirmed", txID) - } - } - - if len(ret.space) > 0 { - info, _, err := cli.Info(ret.space) - if err != nil { - color.Red("cannot get prefix info %v", err) - return ids.Empty, 0, err - } - PPInfo(info) + if err := handleConfirmation(ctx, ret, cli, txID, priv); err != nil { + return ids.Empty, 0, err } - return txID, txCost, nil } @@ -149,16 +131,26 @@ func SignIssueRawTx( return ids.Empty, 0, err } + if err := handleConfirmation(ctx, ret, cli, txID, priv); err != nil { + return ids.Empty, 0, err + } + return txID, utx.GetPrice() * utx.FeeUnits(g), nil +} + +func handleConfirmation( + ctx context.Context, ret *Op, cli Client, + txID ids.ID, priv *ecdsa.PrivateKey, +) error { if ret.pollTx { color.Green("issued transaction %s (now polling)", txID) confirmed, err := cli.PollTx(ctx, txID) if err != nil { - return ids.Empty, 0, err + return err } if !confirmed { color.Yellow("transaction %s not confirmed", txID) } else { - color.Green("transaction %s confirmed", txID) + color.Yellow("transaction %s confirmed", txID) } } @@ -166,17 +158,27 @@ func SignIssueRawTx( info, _, err := cli.Info(ret.space) if err != nil { color.Red("cannot get prefix info %v", err) - return ids.Empty, 0, err + return err } PPInfo(info) } - return txID, utx.GetPrice() * utx.FeeUnits(g), nil + if ret.balance { + addr := crypto.PubkeyToAddress(priv.PublicKey) + b, err := cli.Balance(addr) + if err != nil { + return err + } + color.Cyan("Address=%s Balance=%d", addr, b) + } + + return nil } type Op struct { - pollTx bool - space string + pollTx bool + space string + balance bool } type OpOption func(*Op) @@ -196,3 +198,7 @@ func WithPollTx() OpOption { func WithInfo(space string) OpOption { return func(op *Op) { op.space = space } } + +func WithBalance() OpOption { + return func(op *Op) { op.balance = true } +} diff --git a/cmd/spacescli/cmd/activity.go b/cmd/spacescli/cmd/activity.go index c7d44272..efd3bc53 100644 --- a/cmd/spacescli/cmd/activity.go +++ b/cmd/spacescli/cmd/activity.go @@ -18,7 +18,6 @@ var activityCmd = &cobra.Command{ RunE: activityFunc, } -// TODO: move all this to a separate client code func activityFunc(cmd *cobra.Command, args []string) error { if len(args) != 0 { fmt.Fprintf(os.Stderr, "expected exactly 0 arguments, got %d", len(args)) diff --git a/cmd/spacescli/cmd/claim.go b/cmd/spacescli/cmd/claim.go index 8b6415a9..98f843d2 100644 --- a/cmd/spacescli/cmd/claim.go +++ b/cmd/spacescli/cmd/claim.go @@ -19,40 +19,22 @@ import ( ) var claimCmd = &cobra.Command{ - Use: "claim [options] ", - Short: "Claims the given prefix", + Use: "claim [options] ", + Short: "Claims the given space", Long: ` -Claims the given prefix by issuing claim transaction -with the prefix information. +Claims the given space by issuing claim transaction +with the space information. # Issues "ClaimTx" for the ownership of "hello.avax". -# "hello.avax" is the prefix (or namespace) +# "hello.avax" is the space (or namespace) $ spaces-cli claim hello.avax <", - Short: "Deletes a key-value pair for the given prefix", + Use: "delete [options] ", + Short: "Deletes a key-value pair for the given space", RunE: deleteFunc, } -// TODO: move all this to a separate client code func deleteFunc(cmd *cobra.Command, args []string) error { priv, err := crypto.LoadECDSA(privateKeyFile) if err != nil { @@ -36,17 +35,15 @@ func deleteFunc(cmd *cobra.Command, args []string) error { Key: key, } - opts := []client.OpOption{client.WithPollTx(), client.WithInfo(space)} - _, cost, err := client.SignIssueRawTx(context.Background(), cli, utx, priv, opts...) - if err != nil { - return err + opts := []client.OpOption{client.WithPollTx()} + if verbose { + opts = append(opts, client.WithInfo(space)) + opts = append(opts, client.WithBalance()) } - - addr := crypto.PubkeyToAddress(priv.PublicKey) - b, err := cli.Balance(addr) - if err != nil { + if _, _, err := client.SignIssueRawTx(context.Background(), cli, utx, priv, opts...); err != nil { return err } - color.Cyan("Address=%s Balance=%d Cost=%d", addr, b, cost) + + color.Green("deleted %s from %s", key, space) return nil } diff --git a/cmd/spacescli/cmd/genesis.go b/cmd/spacescli/cmd/genesis.go index b79eb06e..fc86a934 100644 --- a/cmd/spacescli/cmd/genesis.go +++ b/cmd/spacescli/cmd/genesis.go @@ -44,7 +44,7 @@ func init() { &claimReward, "claim-reward", -1, - "seconds until a prefix will expire after being claimed", + "seconds until a spaces will expire after being claimed", ) genesisCmd.PersistentFlags().StringVar( &airdropHash, diff --git a/cmd/spacescli/cmd/info.go b/cmd/spacescli/cmd/info.go index a644f8f9..35ca6e70 100644 --- a/cmd/spacescli/cmd/info.go +++ b/cmd/spacescli/cmd/info.go @@ -20,7 +20,6 @@ var infoCmd = &cobra.Command{ RunE: infoFunc, } -// TODO: move all this to a separate client code func infoFunc(cmd *cobra.Command, args []string) error { if len(args) != 1 { fmt.Fprintf(os.Stderr, "expected exactly 1 argument, got %d", len(args)) diff --git a/cmd/spacescli/cmd/lifeline.go b/cmd/spacescli/cmd/lifeline.go index f2e1e63c..66e4594e 100644 --- a/cmd/spacescli/cmd/lifeline.go +++ b/cmd/spacescli/cmd/lifeline.go @@ -20,12 +20,11 @@ import ( ) var lifelineCmd = &cobra.Command{ - Use: "lifeline [options] ", - Short: "Extends the life of a given prefix", + Use: "lifeline [options] ", + Short: "Extends the life of a given space", RunE: lifelineFunc, } -// TODO: move all this to a separate client code func lifelineFunc(cmd *cobra.Command, args []string) error { priv, err := crypto.LoadECDSA(privateKeyFile) if err != nil { @@ -41,18 +40,16 @@ func lifelineFunc(cmd *cobra.Command, args []string) error { Units: units, } - opts := []client.OpOption{client.WithPollTx(), client.WithInfo(space)} - _, cost, err := client.SignIssueRawTx(context.Background(), cli, utx, priv, opts...) - if err != nil { - return err + opts := []client.OpOption{client.WithPollTx()} + if verbose { + opts = append(opts, client.WithInfo(space)) + opts = append(opts, client.WithBalance()) } - - addr := crypto.PubkeyToAddress(priv.PublicKey) - b, err := cli.Balance(addr) - if err != nil { + if _, _, err := client.SignIssueRawTx(context.Background(), cli, utx, priv, opts...); err != nil { return err } - color.Cyan("Address=%s Balance=%d Cost=%d", addr, b, cost) + + color.Green("extended life of %s by %d units", space, units) return nil } @@ -68,7 +65,7 @@ func getLifelineOp(args []string) (space string, units uint64) { // check here first before parsing in case "pfx" is empty if err := parser.CheckContents(space); err != nil { - fmt.Fprintf(os.Stderr, "failed to verify prefix %v", err) + fmt.Fprintf(os.Stderr, "failed to verify space %v", err) os.Exit(128) } diff --git a/cmd/spacescli/cmd/move.go b/cmd/spacescli/cmd/move.go index 73670cf1..fd6d9a16 100644 --- a/cmd/spacescli/cmd/move.go +++ b/cmd/spacescli/cmd/move.go @@ -24,7 +24,6 @@ var moveCmd = &cobra.Command{ RunE: moveFunc, } -// TODO: move all this to a separate client code func moveFunc(cmd *cobra.Command, args []string) error { priv, err := crypto.LoadECDSA(privateKeyFile) if err != nil { @@ -41,17 +40,15 @@ func moveFunc(cmd *cobra.Command, args []string) error { } opts := []client.OpOption{client.WithPollTx()} - _, cost, err := client.SignIssueRawTx(context.Background(), cli, utx, priv, opts...) - if err != nil { - return err + if verbose { + opts = append(opts, client.WithInfo(space)) + opts = append(opts, client.WithBalance()) } - - addr := crypto.PubkeyToAddress(priv.PublicKey) - b, err := cli.Balance(addr) - if err != nil { + if _, _, err := client.SignIssueRawTx(context.Background(), cli, utx, priv, opts...); err != nil { return err } - color.Cyan("Address=%s Balance=%d Cost=%d", addr, b, cost) + + color.Green("moved %s to %s", space, to.Hex()) return nil } diff --git a/cmd/spacescli/cmd/resolve-file.go b/cmd/spacescli/cmd/resolve-file.go index 0badb0a5..bfb0a2c1 100644 --- a/cmd/spacescli/cmd/resolve-file.go +++ b/cmd/spacescli/cmd/resolve-file.go @@ -8,6 +8,7 @@ import ( "fmt" "os" + "github.com/fatih/color" "github.com/spf13/cobra" "github.com/ava-labs/spacesvm/client" @@ -20,7 +21,6 @@ var resolveFileCmd = &cobra.Command{ RunE: resolveFileFunc, } -// TODO: move all this to a separate client code func resolveFileFunc(cmd *cobra.Command, args []string) error { if len(args) != 2 { fmt.Fprintf(os.Stderr, "expected exactly 2 argument, got %d", len(args)) @@ -41,5 +41,10 @@ func resolveFileFunc(cmd *cobra.Command, args []string) error { defer f.Close() cli := client.New(uri, requestTimeout) - return tree.Download(cli, args[0], f) + if err := tree.Download(cli, args[0], f); err != nil { + return err + } + + color.Green("resolved file %s", args[0]) + return nil } diff --git a/cmd/spacescli/cmd/resolve.go b/cmd/spacescli/cmd/resolve.go index ee69d75e..367fbaaf 100644 --- a/cmd/spacescli/cmd/resolve.go +++ b/cmd/spacescli/cmd/resolve.go @@ -20,7 +20,6 @@ var resolveCmd = &cobra.Command{ RunE: resolveFunc, } -// TODO: move all this to a separate client code func resolveFunc(cmd *cobra.Command, args []string) error { if len(args) != 1 { fmt.Fprintf(os.Stderr, "expected exactly 1 argument, got %d", len(args)) @@ -38,5 +37,6 @@ func resolveFunc(cmd *cobra.Command, args []string) error { return err } color.Yellow("Metadata: %s", string(hr)) + color.Green("resolved %s", args[0]) return nil } diff --git a/cmd/spacescli/cmd/root.go b/cmd/spacescli/cmd/root.go index 71f4cf38..cb9dcb57 100644 --- a/cmd/spacescli/cmd/root.go +++ b/cmd/spacescli/cmd/root.go @@ -19,6 +19,7 @@ const ( var ( privateKeyFile string uri string + verbose bool workDir string rootCmd = &cobra.Command{ @@ -63,7 +64,13 @@ func init() { &uri, "endpoint", "https://api.tryspaces.xyz", - "RPC Endpoint for VM", + "RPC endpoint for VM", + ) + rootCmd.PersistentFlags().BoolVar( + &verbose, + "verbose", + false, + "Print verbose information about operations", ) } diff --git a/cmd/spacescli/cmd/set-file.go b/cmd/spacescli/cmd/set-file.go index 931f8e50..55dd88ed 100644 --- a/cmd/spacescli/cmd/set-file.go +++ b/cmd/spacescli/cmd/set-file.go @@ -23,7 +23,6 @@ var setFileCmd = &cobra.Command{ RunE: setFileFunc, } -// TODO: move all this to a separate client code func setFileFunc(cmd *cobra.Command, args []string) error { priv, err := crypto.LoadECDSA(privateKeyFile) if err != nil { @@ -40,16 +39,12 @@ func setFileFunc(cmd *cobra.Command, args []string) error { } // TODO: protect against overflow - if _, err := tree.Upload(context.Background(), cli, priv, space, f, int(g.MaxValueSize)); err != nil { - return err - } - - addr := crypto.PubkeyToAddress(priv.PublicKey) - b, err := cli.Balance(addr) + path, err := tree.Upload(context.Background(), cli, priv, space, f, int(g.MaxValueSize)) if err != nil { return err } - color.Cyan("Address=%s Balance=%d", addr, b) + + color.Green("uploaded file %s", path) return nil } diff --git a/cmd/spacescli/cmd/set.go b/cmd/spacescli/cmd/set.go index b4144036..02c1a366 100644 --- a/cmd/spacescli/cmd/set.go +++ b/cmd/spacescli/cmd/set.go @@ -18,30 +18,30 @@ import ( ) var setCmd = &cobra.Command{ - Use: "set [options] ", - Short: "Writes a key-value pair for the given prefix", + Use: "set [options] ", + Short: "Writes a key-value pair for the given space", Long: ` Issues "SetTx" to write a key-value pair. -The prefix is automatically parsed with the delimiter "/". +The space is automatically parsed with the delimiter "/". When given a key "foo/hello", the "set" creates the transaction -with "foo" as prefix and "hello" as key. The prefix/key cannot +with "foo" as space and "hello" as key. The space/key cannot have more than one delimiter (e.g., "foo/hello/world" is invalid) in order to maintain the flat key space. -It assumes the prefix is already claimed via "spaces-cli claim". +It assumes the space is already claimed via "spaces-cli claim". Otherwise, the set transaction will fail. -# claims the prefix "hello.avax" -# "hello.avax" is the prefix (or namespace) +# claims the space "hello.avax" +# "hello.avax" is the space (or namespace) $ spaces-cli claim hello.avax < Date: Tue, 18 Jan 2022 21:56:32 -0800 Subject: [PATCH 03/15] more README scoping --- README.md | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 4388d697..d7b585e3 100644 --- a/README.md +++ b/README.md @@ -21,33 +21,31 @@ You could build... * dApp Metadata Backend * Twitter Feed-like -## -More complex example than timestampvm but simpler than subnet-evm - ## How it Works -### Claim +### Flow +#### Claim -#### Community support +##### Community support -### Set/Delete +#### Set/Delete -#### Arbitrary Size File Support (using CLI) +##### Arbitrary Size File Support (using CLI) -### Resolve +#### Resolve -### Transfer +#### Transfer -### Move +#### Move -## Wallet Support: `eth_typedSignedData` +### Wallet Support: `eth_typedSignedData` TODO: Insert image of signing using MM -## Fee Mechanisms +### Fee Mechanisms Claim Desirability + Decay Rate FeeUnits vs Load Units Expiry Rate vs Units -## Space Rewards +### Space Rewards Lottery allocation X% of fee ### Genesis Allocation @@ -58,11 +56,15 @@ twice. _If you are interested in running the VM, not using it. Jump to [Running the VM](#running-the-vm)._ -### Public Beta +Public Beta... + +### tryspaces.xyz What better way to understand how this works than to see it in action? TODO: insert try spaces image + link +Hooked up to public beta + ### spaces-cli _To build the CLI, run `./scripts/build.sh`. It will be placed in `./build/spaces-cli` and `$GOBIN/spaces-cli`._ @@ -75,26 +77,27 @@ Usage: Available Commands: activity View recent activity on the network - claim Claims the given prefix + claim Claims the given space completion generate the autocompletion script for the specified shell create Creates a new key in the default location - delete Deletes a key-value pair for the given prefix + delete Deletes a key-value pair for the given space delete-file Deletes all hashes reachable from root file identifier genesis Creates a new genesis in the default location help Help about any command info Reads space info and all values at space - lifeline Extends the life of a given prefix + lifeline Extends the life of a given space move Transfers a space to another address resolve Reads a value at space/key resolve-file Reads a file at space/key and saves it to disk - set Writes a key-value pair for the given prefix + set Writes a key-value pair for the given space set-file Writes a file to the given space transfer Transfers units to another address Flags: - --endpoint string RPC Endpoint for VM (default "https://memeshowdown.com") + --endpoint string RPC endpoint for VM (default "https://api.tryspaces.xyz") -h, --help help for spaces-cli --private-key-file string private key file path (default ".spaces-cli-pk") + --verbose Print verbose information about operations Use "spaces-cli [command] --help" for more information about a command. ``` From 4b0cadae1d6be9a44a14d6343984965b45beff0c Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Tue, 18 Jan 2022 22:00:31 -0800 Subject: [PATCH 04/15] remove work terms --- chain/errors.go | 2 +- mempool/mempool_test.go | 8 ++++---- vm/chain_vm.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/chain/errors.go b/chain/errors.go index bb8b7aa9..ba513a6b 100644 --- a/chain/errors.go +++ b/chain/errors.go @@ -18,7 +18,7 @@ var ( ErrNoTxs = errors.New("no transactions") ErrInvalidCost = errors.New("invalid block cost") ErrInvalidPrice = errors.New("invalid price") - ErrInsufficientSurplus = errors.New("insufficient surplus difficulty") + ErrInsufficientSurplus = errors.New("insufficient surplus fee") ErrParentBlockNotVerified = errors.New("parent block not verified or accepted") // Tx Correctness diff --git a/mempool/mempool_test.go b/mempool/mempool_test.go index e49f538e..9eb7a402 100644 --- a/mempool/mempool_test.go +++ b/mempool/mempool_test.go @@ -45,11 +45,11 @@ func TestMempool(t *testing.T) { t.Fatalf("tx %s was not added", tx.ID()) } } - if _, diff := txm.PeekMax(); diff != 250 { - t.Fatalf("price expected 250, got %d", diff) + if _, price := txm.PeekMax(); price != 250 { + t.Fatalf("price expected 250, got %d", price) } - if _, diff := txm.PeekMin(); diff != 200 { - t.Fatalf("price expected 200, got %d", diff) + if _, price := txm.PeekMin(); price != 200 { + t.Fatalf("price expected 200, got %d", price) } if length := txm.Len(); length != 3 { t.Fatalf("length expected 3, got %d", length) diff --git a/vm/chain_vm.go b/vm/chain_vm.go index c3abd312..34cecba3 100644 --- a/vm/chain_vm.go +++ b/vm/chain_vm.go @@ -103,7 +103,7 @@ func (vm *VM) ExecutionContext(currTime int64, lastBlock *chain.StatelessBlock) nextCost = lastBlock.Cost } - // compute new min difficulty + // compute new min price nextPrice := lastBlock.Price if recentUnits > vm.targetRangeUnits { nextPrice++ From b3c2c9eb62bbc2b35126aefdbff6df5af2e83e0c Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Tue, 18 Jan 2022 22:08:02 -0800 Subject: [PATCH 05/15] remove all usage of outdated words --- chain/block.go | 2 +- chain/builder.go | 4 +-- chain/claim_tx.go | 2 +- chain/claim_tx_test.go | 14 ++++----- chain/lifeline_tx_test.go | 4 +-- chain/move_tx_test.go | 8 ++--- chain/set_tx_test.go | 6 ++-- chain/storage.go | 18 +++++------ chain/storage_test.go | 44 +++++++++++++-------------- chain/transfer_tx_test.go | 2 +- client/helper.go | 4 +-- cmd/spacescli/cmd/lifeline.go | 2 +- mempool/mempool_benchmark_test.go | 6 ++-- tests/e2e/e2e_test.go | 32 +++++++++---------- tests/integration/integration_test.go | 2 +- vm/vm.go | 2 +- 16 files changed, 76 insertions(+), 76 deletions(-) diff --git a/chain/block.go b/chain/block.go index a5279c39..55cce37f 100644 --- a/chain/block.go +++ b/chain/block.go @@ -181,7 +181,7 @@ func (b *StatelessBlock) verify() (*StatelessBlock, *versiondb.Database, error) } onAcceptDB := versiondb.New(parentState) - // Remove all expired prefixes + // Remove all expired spaces if err := ExpireNext(onAcceptDB, parent.Tmstmp, b.Tmstmp, b.vm.IsBootstrapped()); err != nil { return nil, nil, err } diff --git a/chain/builder.go b/chain/builder.go index 46978b72..ed6b4fb5 100644 --- a/chain/builder.go +++ b/chain/builder.go @@ -40,7 +40,7 @@ func BuildBlock(vm VM, preferred ids.ID) (snowman.Block, error) { } vdb := versiondb.New(parentDB) - // Remove all expired prefixes + // Remove all expired spaces if err := ExpireNext(vdb, parent.Tmstmp, b.Tmstmp, true); err != nil { return nil, err } @@ -79,7 +79,7 @@ func BuildBlock(vm VM, preferred ids.ID) (snowman.Block, error) { if err := tvdb.Commit(); err != nil { return nil, err } - // Wait to add prefix until after verification + // Wait to add spaces until after verification b.Txs = append(b.Txs, next) units += nextLoad } diff --git a/chain/claim_tx.go b/chain/claim_tx.go index dd998cf0..e43a734e 100644 --- a/chain/claim_tx.go +++ b/chain/claim_tx.go @@ -35,7 +35,7 @@ func (c *ClaimTx) Execute(t *TransactionContext) error { return err } - // Restrict address prefix to be owned by address + // Restrict address space to be owned by address if len(c.Space) == hexAddressLen && strings.ToLower(t.Sender.Hex()) != c.Space { return ErrAddressMismatch } diff --git a/chain/claim_tx_test.go b/chain/claim_tx_test.go index a272b838..724c1a46 100644 --- a/chain/claim_tx_test.go +++ b/chain/claim_tx_test.go @@ -41,13 +41,13 @@ func TestClaimTx(t *testing.T) { sender common.Address err error }{ - { // invalid claim, [42]byte prefix is reserved for pubkey + { // invalid claim, [42]byte space is reserved for pubkey tx: &ClaimTx{BaseTx: &BaseTx{}, Space: strings.Repeat("a", hexAddressLen)}, blockTime: 1, sender: sender, err: ErrAddressMismatch, }, - { // valid claim, [42]byte prefix is reserved for pubkey + { // valid claim, [42]byte space is reserved for pubkey tx: &ClaimTx{BaseTx: &BaseTx{}, Space: strings.ToLower(sender.Hex())}, blockTime: 1, sender: sender, @@ -86,7 +86,7 @@ func TestClaimTx(t *testing.T) { } for i, tv := range tt { if i > 0 { - // Expire old prefixes between txs + // Expire old spaces between txs if err := ExpireNext(db, tt[i-1].blockTime, tv.blockTime, true); err != nil { t.Fatalf("#%d: ExpireNext errored %v", i, err) } @@ -107,10 +107,10 @@ func TestClaimTx(t *testing.T) { } info, exists, err := GetSpaceInfo(db, []byte(tv.tx.Space)) if err != nil { - t.Fatalf("#%d: failed to get prefix info %v", i, err) + t.Fatalf("#%d: failed to get space info %v", i, err) } if !exists { - t.Fatalf("#%d: failed to find prefix info", i) + t.Fatalf("#%d: failed to find space info", i) } if !bytes.Equal(info.Owner[:], tv.sender[:]) { t.Fatalf("#%d: unexpected owner found (expected pub key %q)", i, string(sender[:])) @@ -130,9 +130,9 @@ func TestClaimTx(t *testing.T) { } _, exists, err := GetSpaceInfo(db, []byte("foo")) if err != nil { - t.Fatalf("failed to get prefix info %v", err) + t.Fatalf("failed to get space info %v", err) } if exists { - t.Fatal("prefix should not exist") + t.Fatal("space should not exist") } } diff --git a/chain/lifeline_tx_test.go b/chain/lifeline_tx_test.go index 76f8a391..67444e73 100644 --- a/chain/lifeline_tx_test.go +++ b/chain/lifeline_tx_test.go @@ -32,7 +32,7 @@ func TestLifelineTx(t *testing.T) { sender common.Address err error }{ - { // invalid when prefix info is missing + { // invalid when space info is missing utx: &LifelineTx{BaseTx: &BaseTx{}, Space: "foo", Units: 1}, blockTime: 1, sender: sender, @@ -50,7 +50,7 @@ func TestLifelineTx(t *testing.T) { sender: sender, err: ErrNonActionable, }, - { // successful lifeline when prefix info and units is not missing + { // successful lifeline when space info and units is not missing utx: &LifelineTx{BaseTx: &BaseTx{}, Space: "foo", Units: 1}, blockTime: 1, sender: sender, diff --git a/chain/move_tx_test.go b/chain/move_tx_test.go index 98230c6f..59f461b5 100644 --- a/chain/move_tx_test.go +++ b/chain/move_tx_test.go @@ -55,14 +55,14 @@ func TestMoveTx(t *testing.T) { } // Items: transfer without balance, transfer with small balance, transfer some balance, transfer from - // account that now has balance, transfer prefix, transfer to self + // account that now has balance, transfer space, transfer to self tt := []struct { utx UnsignedTransaction blockTime uint64 sender common.Address err error }{ - { // invalid when prefix is not owned + { // invalid when space is not owned utx: &MoveTx{BaseTx: &BaseTx{}, Space: "foo", To: sender3}, blockTime: 1, sender: sender, @@ -80,13 +80,13 @@ func TestMoveTx(t *testing.T) { sender: sender, err: ErrNonActionable, }, - { // successful prefix transfer + { // successful space transfer utx: &MoveTx{BaseTx: &BaseTx{}, Space: "foo", To: sender3}, blockTime: 1, sender: sender, err: nil, }, - { // prefix looking bad + { // space looking bad utx: &MoveTx{BaseTx: &BaseTx{}, Space: "foo/", To: sender3}, blockTime: 1, sender: sender, diff --git a/chain/set_tx_test.go b/chain/set_tx_test.go index c03401a5..5a1d9e47 100644 --- a/chain/set_tx_test.go +++ b/chain/set_tx_test.go @@ -227,7 +227,7 @@ func TestSetTx(t *testing.T) { } for i, tv := range tt { if i > 0 { - // Expire old prefixes between txs + // Expire old spaces between txs if err := ExpireNext(db, tt[i-1].blockTime, tv.blockTime, true); err != nil { t.Fatalf("#%d: ExpireNext errored %v", i, err) } @@ -261,10 +261,10 @@ func TestSetTx(t *testing.T) { case *ClaimTx: // "ClaimTx.Execute" must persist "SpaceInfo" info, exists, err := GetSpaceInfo(db, []byte(tp.Space)) if err != nil { - t.Fatalf("#%d: failed to get prefix info %v", i, err) + t.Fatalf("#%d: failed to get space info %v", i, err) } if !exists { - t.Fatalf("#%d: failed to find prefix info", i) + t.Fatalf("#%d: failed to find space info", i) } if !bytes.Equal(info.Owner[:], tv.sender[:]) { t.Fatalf("#%d: unexpected owner found (expected pub key %q)", i, string(sender[:])) diff --git a/chain/storage.go b/chain/storage.go index 77f663d5..d8e18bd6 100644 --- a/chain/storage.go +++ b/chain/storage.go @@ -403,32 +403,32 @@ func ExpireNext(db database.Database, rparent int64, rcurrent int64, bootstrappe } // [space] - pfx := cursor.Value() + spc := cursor.Value() // [infoPrefix] + [delimiter] + [space] - k := SpaceInfoKey(pfx) + k := SpaceInfoKey(spc) if err := db.Delete(k); err != nil { return err } - expired, rpfx, err := extractSpecificTimeKey(curKey) + expired, rspc, err := extractSpecificTimeKey(curKey) if err != nil { return err } if bootstrapped { // [pruningPrefix] + [delimiter] + [timestamp] + [delimiter] + [rawSpace] - k = PrefixPruningKey(expired, rpfx) + k = PrefixPruningKey(expired, rspc) if err := db.Put(k, nil); err != nil { return err } } else { // If we are not yet bootstrapped, we should delete the dangling value keys // immediately instead of clearing async. - if err := database.ClearPrefix(db, db, SpaceValueKey(rpfx, nil)); err != nil { + if err := database.ClearPrefix(db, db, SpaceValueKey(rspc, nil)); err != nil { return err } } - log.Debug("space expired", "space", string(pfx)) + log.Debug("space expired", "space", string(spc)) } return nil } @@ -448,7 +448,7 @@ func PruneNext(db database.Database, limit int) (removals int, err error) { if bytes.Compare(curKey, endKey) > 0 { // curKey > endKey; end search break } - _, rpfx, err := extractSpecificTimeKey(curKey) + _, rspc, err := extractSpecificTimeKey(curKey) if err != nil { return removals, err } @@ -456,10 +456,10 @@ func PruneNext(db database.Database, limit int) (removals int, err error) { return removals, err } // [keyPrefix] + [delimiter] + [rawSpace] + [delimiter] + [key] - if err := database.ClearPrefix(db, db, SpaceValueKey(rpfx, nil)); err != nil { + if err := database.ClearPrefix(db, db, SpaceValueKey(rspc, nil)); err != nil { return removals, err } - log.Debug("rspace pruned", "rspace", rpfx.Hex()) + log.Debug("rspace pruned", "rspace", rspc.Hex()) removals++ } return removals, nil diff --git a/chain/storage_test.go b/chain/storage_test.go index e0fbcde5..0230173a 100644 --- a/chain/storage_test.go +++ b/chain/storage_test.go @@ -19,18 +19,18 @@ func TestSpaceValueKey(t *testing.T) { t.Parallel() tt := []struct { - rpfx ids.ShortID + rspc ids.ShortID key []byte valueKey []byte }{ { - rpfx: ids.ShortID{0x1}, + rspc: ids.ShortID{0x1}, key: []byte("hello"), valueKey: append([]byte{keyPrefix}, []byte("/\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00/hello")...), //nolint:lll }, } for i, tv := range tt { - vv := SpaceValueKey(tv.rpfx, tv.key) + vv := SpaceValueKey(tv.rspc, tv.key) if !bytes.Equal(tv.valueKey, vv) { t.Fatalf("#%d: value expected %q, got %q", i, tv.valueKey, vv) } @@ -41,16 +41,16 @@ func TestSpaceInfoKey(t *testing.T) { t.Parallel() tt := []struct { - pfx []byte + spc []byte infoKey []byte }{ { - pfx: []byte("foo"), + spc: []byte("foo"), infoKey: append([]byte{infoPrefix}, []byte("/foo")...), }, } for i, tv := range tt { - vv := SpaceInfoKey(tv.pfx) + vv := SpaceInfoKey(tv.spc) if !bytes.Equal(tv.infoKey, vv) { t.Fatalf("#%d: value expected %q, got %q", i, tv.infoKey, vv) } @@ -105,23 +105,23 @@ func TestPutSpaceInfoAndKey(t *testing.T) { db := memdb.New() defer db.Close() - pfx := []byte("foo") + spc := []byte("foo") k, v := []byte("k"), &ValueMeta{} - // expect failures for non-existing prefixInfo - if ok, err := HasSpace(db, pfx); ok || err != nil { + // expect failures for non-existing spaceInfo + if ok, err := HasSpace(db, spc); ok || err != nil { t.Fatalf("unexpected ok %v, err %v", ok, err) } - if ok, err := HasSpaceKey(db, pfx, k); ok || err != nil { + if ok, err := HasSpaceKey(db, spc, k); ok || err != nil { t.Fatalf("unexpected ok %v, err %v", ok, err) } - if err := PutSpaceKey(db, pfx, k, v); !errors.Is(err, ErrSpaceMissing) { + if err := PutSpaceKey(db, spc, k, v); !errors.Is(err, ErrSpaceMissing) { t.Fatalf("unexpected error %v, expected %v", err, ErrSpaceMissing) } if err := PutSpaceInfo( db, - pfx, + spc, &SpaceInfo{ RawSpace: ids.ShortID{0x1}, }, @@ -129,31 +129,31 @@ func TestPutSpaceInfoAndKey(t *testing.T) { ); err != nil { t.Fatal(err) } - if err := PutSpaceKey(db, pfx, k, v); err != nil { + if err := PutSpaceKey(db, spc, k, v); err != nil { t.Fatalf("unexpected error %v", err) } - // expect success for existing prefixInfo - if ok, err := HasSpace(db, pfx); !ok || err != nil { + // expect success for existing spaceInfo + if ok, err := HasSpace(db, spc); !ok || err != nil { t.Fatalf("unexpected ok %v, err %v", ok, err) } - if ok, err := HasSpaceKey(db, pfx, k); !ok || err != nil { + if ok, err := HasSpaceKey(db, spc, k); !ok || err != nil { t.Fatalf("unexpected ok %v, err %v", ok, err) } } func TestSpecificTimeKey(t *testing.T) { - rpfx0 := ids.ShortID{'k'} - k := PrefixExpiryKey(100, rpfx0) - ts, rpfx, err := extractSpecificTimeKey(k) + rspc0 := ids.ShortID{'k'} + k := PrefixExpiryKey(100, rspc0) + ts, rspc, err := extractSpecificTimeKey(k) if err != nil { t.Fatal(err) } if ts != 100 { t.Fatalf("unexpected timestamp %d, expected 100", ts) } - if rpfx != rpfx0 { - t.Fatalf("unexpected rawPrefix %v, expected %v", rpfx, rpfx0) + if rspc != rspc0 { + t.Fatalf("unexpected rawSpace %v, expected %v", rspc, rspc0) } if _, _, err = extractSpecificTimeKey(k[:10]); !errors.Is(err, ErrInvalidKeyFormat) { @@ -336,7 +336,7 @@ func TestGetAllValueMetas(t *testing.T) { } for i, tv := range tt { if i > 0 { - // Expire old prefixes between txs + // Expire old spaces between txs if err := ExpireNext(db, tt[i-1].blockTime, tv.blockTime, true); err != nil { t.Fatalf("#%d: ExpireNext errored %v", i, err) } diff --git a/chain/transfer_tx_test.go b/chain/transfer_tx_test.go index a87fe0dc..a459526b 100644 --- a/chain/transfer_tx_test.go +++ b/chain/transfer_tx_test.go @@ -54,7 +54,7 @@ func TestTransferTx(t *testing.T) { } // Items: transfer without balance, transfer with small balance, transfer some balance, transfer from - // account that now has balance, transfer prefix, transfer to self + // account that now has balance, transfer space, transfer to self tt := []struct { utx UnsignedTransaction blockTime uint64 diff --git a/client/helper.go b/client/helper.go index 3cac41eb..eb7f4728 100644 --- a/client/helper.go +++ b/client/helper.go @@ -21,7 +21,7 @@ import ( func PPInfo(info *chain.SpaceInfo) { expiry := time.Unix(int64(info.Expiry), 0) color.Blue( - "raw prefix %s: units=%d expiry=%v (%v remaining)", + "raw space %s: units=%d expiry=%v (%v remaining)", info.RawSpace, info.Units, expiry, time.Until(expiry), ) } @@ -157,7 +157,7 @@ func handleConfirmation( if len(ret.space) > 0 { info, _, err := cli.Info(ret.space) if err != nil { - color.Red("cannot get prefix info %v", err) + color.Red("cannot get space info %v", err) return err } PPInfo(info) diff --git a/cmd/spacescli/cmd/lifeline.go b/cmd/spacescli/cmd/lifeline.go index 66e4594e..0bf2c3a3 100644 --- a/cmd/spacescli/cmd/lifeline.go +++ b/cmd/spacescli/cmd/lifeline.go @@ -63,7 +63,7 @@ func getLifelineOp(args []string) (space string, units uint64) { splits := strings.Split(space, "/") space = splits[0] - // check here first before parsing in case "pfx" is empty + // check here first before parsing in case "space" is empty if err := parser.CheckContents(space); err != nil { fmt.Fprintf(os.Stderr, "failed to verify space %v", err) os.Exit(128) diff --git a/mempool/mempool_benchmark_test.go b/mempool/mempool_benchmark_test.go index 43c6e702..dbc67b43 100644 --- a/mempool/mempool_benchmark_test.go +++ b/mempool/mempool_benchmark_test.go @@ -64,8 +64,8 @@ func createTestMempool( g := chain.DefaultGenesis() txs := make([]*chain.Transaction, n) for i := 0; i < n; i++ { - pfx := make([]byte, 8) - _, err := rand.Read(pfx) + spc := make([]byte, 8) + _, err := rand.Read(spc) if err != nil { b.Fatal(err) } @@ -75,7 +75,7 @@ func createTestMempool( BaseTx: &chain.BaseTx{ BlockID: blks[i%blksN], }, - Space: string(pfx), + Space: string(spc), }, } sig, err := chain.Sign(tx.DigestHash(), priv) diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 9d91a9ec..0d98e0c8 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -161,9 +161,9 @@ var _ = ginkgo.Describe("[Claim/SetTx]", func() { gomega.Ω(claimed).Should(gomega.BeTrue()) }) - ginkgo.By("check prefix to check if ClaimTx has been accepted from all nodes", func() { + ginkgo.By("check space to check if ClaimTx has been accepted from all nodes", func() { for _, inst := range instances { - color.Blue("checking prefix on %q", inst.uri) + color.Blue("checking space on %q", inst.uri) pf, _, err := inst.cli.Info(space) gomega.Ω(err).To(gomega.BeNil()) gomega.Ω(pf.Units).To(gomega.Equal(uint64(1))) @@ -198,9 +198,9 @@ var _ = ginkgo.Describe("[Claim/SetTx]", func() { gomega.Ω(err).Should(gomega.BeNil()) }) - ginkgo.By("check prefix to check if SetTx has been accepted from all nodes", func() { + ginkgo.By("check space to check if SetTx has been accepted from all nodes", func() { for _, inst := range instances { - color.Blue("checking prefix on %q", inst.uri) + color.Blue("checking space on %q", inst.uri) pf, _, err := inst.cli.Info(space) gomega.Ω(err).To(gomega.BeNil()) gomega.Ω(pf.Units).To(gomega.Equal(uint64(2))) @@ -248,9 +248,9 @@ var _ = ginkgo.Describe("[Claim/SetTx]", func() { gomega.Ω(err).Should(gomega.BeNil()) }) - ginkgo.By("check prefix to check if SetTx has been accepted from all nodes", func() { + ginkgo.By("check space to check if SetTx has been accepted from all nodes", func() { for _, inst := range instances { - color.Blue("checking prefix on %q", inst.uri) + color.Blue("checking space on %q", inst.uri) pf, _, err := inst.cli.Info(space) gomega.Ω(err).To(gomega.BeNil()) gomega.Ω(pf.Units).To(gomega.Equal(uint64(22))) @@ -296,9 +296,9 @@ var _ = ginkgo.Describe("[Claim/SetTx]", func() { gomega.Ω(err).Should(gomega.BeNil()) }) - ginkgo.By("check prefix to check if SetTx has been accepted from all nodes", func() { + ginkgo.By("check space to check if SetTx has been accepted from all nodes", func() { for _, inst := range instances { - color.Blue("checking prefix on %q", inst.uri) + color.Blue("checking space on %q", inst.uri) pf, _, err := inst.cli.Info(space) gomega.Ω(err).To(gomega.BeNil()) gomega.Ω(pf.Units).To(gomega.Equal(uint64(1))) @@ -344,9 +344,9 @@ var _ = ginkgo.Describe("[Claim/SetTx]", func() { gomega.Ω(claimed).Should(gomega.BeTrue()) }) - ginkgo.By("check prefix to check if ClaimTx has been accepted from all nodes", func() { + ginkgo.By("check space to check if ClaimTx has been accepted from all nodes", func() { for _, inst := range instances { - color.Blue("checking prefix on %q", inst.uri) + color.Blue("checking space on %q", inst.uri) pf, _, err := inst.cli.Info(space) gomega.Ω(err).To(gomega.BeNil()) gomega.Ω(pf.Units).To(gomega.Equal(uint64(1))) @@ -379,9 +379,9 @@ var _ = ginkgo.Describe("[Claim/SetTx]", func() { gomega.Ω(err).Should(gomega.BeNil()) }) - ginkgo.By("check prefix to check if SetTx has been accepted from all nodes", func() { + ginkgo.By("check space to check if SetTx has been accepted from all nodes", func() { for _, inst := range instances { - color.Blue("checking prefix on %q", inst.uri) + color.Blue("checking space on %q", inst.uri) pf, _, err := inst.cli.Info(space) gomega.Ω(err).To(gomega.BeNil()) gomega.Ω(pf.Units).To(gomega.Equal(uint64(2))) @@ -427,9 +427,9 @@ var _ = ginkgo.Describe("[Claim/SetTx]", func() { gomega.Ω(err).Should(gomega.BeNil()) }) - ginkgo.By("check prefix to check if SetTx has been accepted from all nodes", func() { + ginkgo.By("check space to check if SetTx has been accepted from all nodes", func() { for _, inst := range instances { - color.Blue("checking prefix on %q", inst.uri) + color.Blue("checking space on %q", inst.uri) pf, _, err := inst.cli.Info(space) gomega.Ω(err).To(gomega.BeNil()) gomega.Ω(pf.Units).To(gomega.Equal(uint64(22))) @@ -473,9 +473,9 @@ var _ = ginkgo.Describe("[Claim/SetTx]", func() { gomega.Ω(err).Should(gomega.BeNil()) }) - ginkgo.By("check prefix to check if SetTx has been accepted from all nodes", func() { + ginkgo.By("check space to check if SetTx has been accepted from all nodes", func() { for _, inst := range instances { - color.Blue("checking prefix on %q", inst.uri) + color.Blue("checking space on %q", inst.uri) pf, _, err := inst.cli.Info(space) gomega.Ω(err).To(gomega.BeNil()) gomega.Ω(pf.Units).To(gomega.Equal(uint64(1))) diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 6cc9bb9d..5acf70b8 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -352,7 +352,7 @@ var _ = ginkgo.Describe("Tx Types", func() { expectBlkAccept(instances[0]) }) - ginkgo.By("check prefix after ClaimTx has been accepted", func() { + ginkgo.By("check space after ClaimTx has been accepted", func() { pf, values, err := instances[0].cli.Info(space) gomega.Ω(err).To(gomega.BeNil()) gomega.Ω(pf).NotTo(gomega.BeNil()) diff --git a/vm/vm.go b/vm/vm.go index b41a47f7..72fc82dd 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -384,7 +384,7 @@ func (vm *VM) Submit(txs ...*chain.Transaction) (errs []error) { } vdb := versiondb.New(vm.db) - // Expire outdated prefixes before checking submission validity + // Expire outdated spaces before checking submission validity if err := chain.ExpireNext(vdb, blk.Tmstmp, now, true); err != nil { return []error{err} } From 2bbc0be32c3a73427e21ec5c95bcd1efb1cc5539 Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Tue, 18 Jan 2022 22:09:04 -0800 Subject: [PATCH 06/15] mod tidy --- go.mod | 1 - go.sum | 12 ------------ 2 files changed, 13 deletions(-) diff --git a/go.mod b/go.mod index a1ecbc67..d673a3ce 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,6 @@ require ( github.com/btcsuite/btcutil v1.0.2 // indirect github.com/cespare/xxhash/v2 v2.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/decred/dcrd/dcrec/secp256k1/v3 v3.0.0-20200627015759-01fd2de07837 // indirect github.com/fsnotify/fsnotify v1.5.1 // indirect github.com/go-stack/stack v1.8.0 // indirect github.com/golang/protobuf v1.5.2 // indirect diff --git a/go.sum b/go.sum index b0233008..a6a13805 100644 --- a/go.sum +++ b/go.sum @@ -63,9 +63,7 @@ github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= -github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c3fqvvgKm5o= github.com/VictoriaMetrics/fastcache v1.6.0/go.mod h1:0qHz5QP0GMX4pfmMA/zt5RgfNuXJrTP0zS7DqpHGGTw= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= @@ -146,11 +144,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ= -github.com/decred/dcrd/chaincfg/chainhash v1.0.2 h1:rt5Vlq/jM3ZawwiacWjPa+smINyLRN07EO0cNBV6DGU= github.com/decred/dcrd/chaincfg/chainhash v1.0.2/go.mod h1:BpbrGgrPTr3YJYRN3Bm+D9NuaFd+zGyNeIKgrhCXK60= -github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0= github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= -github.com/decred/dcrd/dcrec/secp256k1/v3 v3.0.0-20200627015759-01fd2de07837 h1:g2cyFTu5FKWhCo7L4hVJ797Q506B4EywA7L9I6OebgA= github.com/decred/dcrd/dcrec/secp256k1/v3 v3.0.0-20200627015759-01fd2de07837/go.mod h1:J70FGZSbzsjecRTiTzER+3f1KZLNaXkuv+yeFTKoxM8= github.com/deepmap/oapi-codegen v1.6.0/go.mod h1:ryDa9AgbELGeB+YEXE1dR53yAjHwFvE9iAUlWl9Al3M= github.com/deepmap/oapi-codegen v1.8.2/go.mod h1:YLgSKSDv/bZQB7N4ws6luhozi3cEdRktEqrX88CvjIw= @@ -204,7 +199,6 @@ github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2 github.com/go-latex/latex v0.0.0-20210118124228-b3d85cf34e07/go.mod h1:CO1AlKB2CSIqUrmQPqA0gdRIlnLEY0gK5JGjh37zN5U= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E= github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= @@ -434,7 +428,6 @@ github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOA github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= -github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-sqlite3 v1.11.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/mattn/go-tty v0.0.0-20180907095812-13ff1204f104/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= @@ -472,7 +465,6 @@ github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+ github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= -github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -530,7 +522,6 @@ github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7z github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFBS8= github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= -github.com/prometheus/tsdb v0.7.1 h1:YZcsG11NqnK4czYLrWd9mpEuAJIHVQLwdrleYfszMAA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/retailnext/hllpp v1.0.1-0.20180308014038-101a6d2f8b52/go.mod h1:RDpi1RftBQPUCDRw6SmxeaREsAaRKnOclghuzp/WRzc= github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRrjvIXnJho= @@ -545,7 +536,6 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo= github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= -github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= @@ -587,9 +577,7 @@ github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69 github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE= -github.com/tklauser/go-sysconf v0.3.5 h1:uu3Xl4nkLzQfXNsWn15rPc/HQCJKObbt1dKJeWp3vU4= github.com/tklauser/go-sysconf v0.3.5/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITnppBXY/rYEFI= -github.com/tklauser/numcpus v0.2.2 h1:oyhllyrScuYI6g+h/zUvNXNp1wy7x8qQy3t/piefldA= github.com/tklauser/numcpus v0.2.2/go.mod h1:x3qojaO3uyYt0i56EW/VUYs7uBvdl2fkfZFu0T9wgjM= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs= From 5dc3f0b538f5aa0127d0ec94ab4e4d4394ea0a51 Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Tue, 18 Jan 2022 22:11:31 -0800 Subject: [PATCH 07/15] speed up expiry of keys --- chain/claim_tx.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chain/claim_tx.go b/chain/claim_tx.go index e43a734e..85882182 100644 --- a/chain/claim_tx.go +++ b/chain/claim_tx.go @@ -55,7 +55,7 @@ func (c *ClaimTx) Execute(t *TransactionContext) error { Created: t.BlockTime, Updated: t.BlockTime, Expiry: t.BlockTime + t.Genesis.ClaimReward, - Units: 1, + Units: t.Genesis.MinClaimFee, } if err := PutSpaceInfo(t.Database, []byte(c.Space), newInfo, 0); err != nil { return err From a196b60f90b878bd15601f221f38af18cf83d5bd Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Tue, 18 Jan 2022 22:24:12 -0800 Subject: [PATCH 08/15] more output tuning --- client/helper.go | 8 ++++---- cmd/spacescli/cmd/resolve-file.go | 11 ++++------- cmd/spacescli/cmd/set-file.go | 2 +- cmd/spacescli/main.go | 5 +++-- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/client/helper.go b/client/helper.go index eb7f4728..a766bd66 100644 --- a/client/helper.go +++ b/client/helper.go @@ -20,7 +20,7 @@ import ( func PPInfo(info *chain.SpaceInfo) { expiry := time.Unix(int64(info.Expiry), 0) - color.Blue( + color.Cyan( "raw space %s: units=%d expiry=%v (%v remaining)", info.RawSpace, info.Units, expiry, time.Until(expiry), ) @@ -28,14 +28,14 @@ func PPInfo(info *chain.SpaceInfo) { func PPActivity(a []*chain.Activity) error { if len(a) == 0 { - color.Blue("no recent activity") + color.Cyan("no recent activity") } for _, item := range a { b, err := json.Marshal(item) if err != nil { return err } - color.Blue(string(b)) + color.Cyan(string(b)) } return nil } @@ -142,7 +142,7 @@ func handleConfirmation( txID ids.ID, priv *ecdsa.PrivateKey, ) error { if ret.pollTx { - color.Green("issued transaction %s (now polling)", txID) + color.Yellow("issued transaction %s (now polling)", txID) confirmed, err := cli.PollTx(ctx, txID) if err != nil { return err diff --git a/cmd/spacescli/cmd/resolve-file.go b/cmd/spacescli/cmd/resolve-file.go index bfb0a2c1..6ffe85d1 100644 --- a/cmd/spacescli/cmd/resolve-file.go +++ b/cmd/spacescli/cmd/resolve-file.go @@ -23,20 +23,17 @@ var resolveFileCmd = &cobra.Command{ func resolveFileFunc(cmd *cobra.Command, args []string) error { if len(args) != 2 { - fmt.Fprintf(os.Stderr, "expected exactly 2 argument, got %d", len(args)) - os.Exit(128) + return fmt.Errorf("expected exactly 2 argument, got %d", len(args)) } filePath := args[1] if _, err := os.Stat(filePath); !errors.Is(err, os.ErrNotExist) { - fmt.Fprintf(os.Stderr, "file already exists %v", err) - os.Exit(128) + return fmt.Errorf("file %s already exists", filePath) } f, err := os.Create(filePath) if err != nil { - fmt.Fprintf(os.Stderr, "failed to create file %v", err) - os.Exit(128) + return fmt.Errorf("failed to create file %s", filePath) } defer f.Close() @@ -45,6 +42,6 @@ func resolveFileFunc(cmd *cobra.Command, args []string) error { return err } - color.Green("resolved file %s", args[0]) + color.Green("resolved file %s and stored at %s", args[0], filePath) return nil } diff --git a/cmd/spacescli/cmd/set-file.go b/cmd/spacescli/cmd/set-file.go index 55dd88ed..0c20710a 100644 --- a/cmd/spacescli/cmd/set-file.go +++ b/cmd/spacescli/cmd/set-file.go @@ -44,7 +44,7 @@ func setFileFunc(cmd *cobra.Command, args []string) error { return err } - color.Green("uploaded file %s", path) + color.Green("uploaded file %s from %s", path, f.Name()) return nil } diff --git a/cmd/spacescli/main.go b/cmd/spacescli/main.go index 313da30a..3bd9602e 100644 --- a/cmd/spacescli/main.go +++ b/cmd/spacescli/main.go @@ -5,15 +5,16 @@ package main import ( - "fmt" "os" + "github.com/fatih/color" + "github.com/ava-labs/spacesvm/cmd/spacescli/cmd" ) func main() { if err := cmd.Execute(); err != nil { - fmt.Fprintf(os.Stderr, "spaces-cli failed %v\n", err) + color.Red("spaces-cli failed: %v", err) os.Exit(1) } os.Exit(0) From a7da33bf40128cb8a168b90625ea589a0cdbca5c Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Tue, 18 Jan 2022 22:28:24 -0800 Subject: [PATCH 09/15] remove 128 exit from client --- cmd/spacescli/cmd/resolve.go | 5 ++--- cmd/spacescli/cmd/set-file.go | 23 +++++++++++------------ 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/cmd/spacescli/cmd/resolve.go b/cmd/spacescli/cmd/resolve.go index 367fbaaf..0795b90b 100644 --- a/cmd/spacescli/cmd/resolve.go +++ b/cmd/spacescli/cmd/resolve.go @@ -6,7 +6,6 @@ package cmd import ( "encoding/json" "fmt" - "os" "github.com/fatih/color" "github.com/spf13/cobra" @@ -22,8 +21,7 @@ var resolveCmd = &cobra.Command{ func resolveFunc(cmd *cobra.Command, args []string) error { if len(args) != 1 { - fmt.Fprintf(os.Stderr, "expected exactly 1 argument, got %d", len(args)) - os.Exit(128) + return fmt.Errorf("expected exactly 1 argument, got %d", len(args)) } cli := client.New(uri, requestTimeout) _, v, vmeta, err := cli.Resolve(args[0]) @@ -37,6 +35,7 @@ func resolveFunc(cmd *cobra.Command, args []string) error { return err } color.Yellow("Metadata: %s", string(hr)) + color.Green("resolved %s", args[0]) return nil } diff --git a/cmd/spacescli/cmd/set-file.go b/cmd/spacescli/cmd/set-file.go index 0c20710a..a0de840b 100644 --- a/cmd/spacescli/cmd/set-file.go +++ b/cmd/spacescli/cmd/set-file.go @@ -29,7 +29,10 @@ func setFileFunc(cmd *cobra.Command, args []string) error { return err } - space, f := getSetFileOp(args) + space, f, err := getSetFileOp(args) + if err != nil { + return err + } defer f.Close() cli := client.New(uri, requestTimeout) @@ -48,29 +51,25 @@ func setFileFunc(cmd *cobra.Command, args []string) error { return nil } -func getSetFileOp(args []string) (space string, f *os.File) { +func getSetFileOp(args []string) (space string, f *os.File, err error) { if len(args) != 2 { - fmt.Fprintf(os.Stderr, "expected exactly 2 arguments, got %d", len(args)) - os.Exit(128) + return "", nil, fmt.Errorf("expected exactly 2 arguments, got %d", len(args)) } spaceKey := args[0] if err := parser.CheckContents(spaceKey); err != nil { - fmt.Fprintf(os.Stderr, "failed to parse space %v", err) - os.Exit(128) + return "", nil, fmt.Errorf("%w: failed to parse space", err) } filePath := args[1] if _, err := os.Stat(filePath); err != nil { - fmt.Fprintf(os.Stderr, "file is not accessible %v", err) - os.Exit(128) + return "", nil, fmt.Errorf("%w: file is not accessible", err) } - f, err := os.Open(filePath) + f, err = os.Open(filePath) if err != nil { - fmt.Fprintf(os.Stderr, "failed to open file %v", err) - os.Exit(128) + return "", nil, fmt.Errorf("%w: failed to open file", err) } - return spaceKey, f + return spaceKey, f, nil } From 9d5fcd1d2225d7af6cf3254b4ffa164c78f4372b Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Tue, 18 Jan 2022 22:56:33 -0800 Subject: [PATCH 10/15] remove os.Exit --- cmd/spacescli/cmd/activity.go | 4 +--- cmd/spacescli/cmd/claim.go | 18 +++++++++--------- cmd/spacescli/cmd/common.go | 12 ++++-------- cmd/spacescli/cmd/delete-file.go | 4 +--- cmd/spacescli/cmd/delete.go | 7 +++++-- cmd/spacescli/cmd/info.go | 4 +--- cmd/spacescli/cmd/lifeline.go | 23 +++++++++++------------ cmd/spacescli/cmd/move.go | 18 +++++++++--------- cmd/spacescli/cmd/set.go | 20 +++++++++----------- cmd/spacescli/cmd/transfer.go | 20 ++++++++++---------- 10 files changed, 60 insertions(+), 70 deletions(-) diff --git a/cmd/spacescli/cmd/activity.go b/cmd/spacescli/cmd/activity.go index efd3bc53..aa1eebe2 100644 --- a/cmd/spacescli/cmd/activity.go +++ b/cmd/spacescli/cmd/activity.go @@ -5,7 +5,6 @@ package cmd import ( "fmt" - "os" "github.com/spf13/cobra" @@ -20,8 +19,7 @@ var activityCmd = &cobra.Command{ func activityFunc(cmd *cobra.Command, args []string) error { if len(args) != 0 { - fmt.Fprintf(os.Stderr, "expected exactly 0 arguments, got %d", len(args)) - os.Exit(128) + return fmt.Errorf("expected exactly 0 arguments, got %d", len(args)) } cli := client.New(uri, requestTimeout) activity, err := cli.RecentActivity() diff --git a/cmd/spacescli/cmd/claim.go b/cmd/spacescli/cmd/claim.go index 98f843d2..d19f274a 100644 --- a/cmd/spacescli/cmd/claim.go +++ b/cmd/spacescli/cmd/claim.go @@ -6,7 +6,6 @@ package cmd import ( "context" "fmt" - "os" "strings" "github.com/ethereum/go-ethereum/crypto" @@ -41,14 +40,17 @@ func claimFunc(cmd *cobra.Command, args []string) error { return err } - space := getClaimOp(args) - cli := client.New(uri, requestTimeout) + space, err := getClaimOp(args) + if err != nil { + return err + } utx := &chain.ClaimTx{ BaseTx: &chain.BaseTx{}, Space: space, } + cli := client.New(uri, requestTimeout) opts := []client.OpOption{client.WithPollTx()} if verbose { opts = append(opts, client.WithInfo(space)) @@ -62,10 +64,9 @@ func claimFunc(cmd *cobra.Command, args []string) error { return nil } -func getClaimOp(args []string) (space string) { +func getClaimOp(args []string) (space string, err error) { if len(args) != 1 { - fmt.Fprintf(os.Stderr, "expected exactly 1 argument, got %d", len(args)) - os.Exit(128) + return "", fmt.Errorf("expected exactly 1 argument, got %d", len(args)) } space = args[0] @@ -74,9 +75,8 @@ func getClaimOp(args []string) (space string) { // check here first before parsing in case "space" is empty if err := parser.CheckContents(space); err != nil { - fmt.Fprintf(os.Stderr, "failed to verify space %v", err) - os.Exit(128) + return "", fmt.Errorf("%w: failed to verify space", err) } - return space + return space, nil } diff --git a/cmd/spacescli/cmd/common.go b/cmd/spacescli/cmd/common.go index b57d33eb..281ae3f0 100644 --- a/cmd/spacescli/cmd/common.go +++ b/cmd/spacescli/cmd/common.go @@ -5,26 +5,22 @@ package cmd import ( "fmt" - "os" "github.com/ava-labs/spacesvm/parser" ) -func getPathOp(args []string) (space string, key string) { +func getPathOp(args []string) (space string, key string, err error) { if len(args) != 1 { - fmt.Fprintf(os.Stderr, "expected exactly 1 argument, got %d", len(args)) - os.Exit(128) + return "", "", fmt.Errorf("expected exactly 1 argument, got %d", len(args)) } // [space/key] == "foo/bar" spaceKey := args[0] - var err error space, key, err = parser.ResolvePath(spaceKey) if err != nil { - fmt.Fprintf(os.Stderr, "failed to parse space %v", err) - os.Exit(128) + return "", "", fmt.Errorf("%w: failed to parse space", err) } - return space, key + return space, key, nil } diff --git a/cmd/spacescli/cmd/delete-file.go b/cmd/spacescli/cmd/delete-file.go index 4c6d9d11..b12ff938 100644 --- a/cmd/spacescli/cmd/delete-file.go +++ b/cmd/spacescli/cmd/delete-file.go @@ -6,7 +6,6 @@ package cmd import ( "context" "fmt" - "os" "github.com/ethereum/go-ethereum/crypto" "github.com/fatih/color" @@ -29,8 +28,7 @@ func deleteFileFunc(cmd *cobra.Command, args []string) error { } if len(args) != 1 { - fmt.Fprintf(os.Stderr, "expected exactly 1 argument, got %d", len(args)) - os.Exit(128) + return fmt.Errorf("expected exactly 1 argument, got %d", len(args)) } cli := client.New(uri, requestTimeout) diff --git a/cmd/spacescli/cmd/delete.go b/cmd/spacescli/cmd/delete.go index 8d6f9592..1ab74c97 100644 --- a/cmd/spacescli/cmd/delete.go +++ b/cmd/spacescli/cmd/delete.go @@ -26,8 +26,10 @@ func deleteFunc(cmd *cobra.Command, args []string) error { return err } - space, key := getPathOp(args) - cli := client.New(uri, requestTimeout) + space, key, err := getPathOp(args) + if err != nil { + return err + } utx := &chain.DeleteTx{ BaseTx: &chain.BaseTx{}, @@ -35,6 +37,7 @@ func deleteFunc(cmd *cobra.Command, args []string) error { Key: key, } + cli := client.New(uri, requestTimeout) opts := []client.OpOption{client.WithPollTx()} if verbose { opts = append(opts, client.WithInfo(space)) diff --git a/cmd/spacescli/cmd/info.go b/cmd/spacescli/cmd/info.go index 35ca6e70..6aa6b6a5 100644 --- a/cmd/spacescli/cmd/info.go +++ b/cmd/spacescli/cmd/info.go @@ -6,7 +6,6 @@ package cmd import ( "encoding/json" "fmt" - "os" "github.com/fatih/color" "github.com/spf13/cobra" @@ -22,8 +21,7 @@ var infoCmd = &cobra.Command{ func infoFunc(cmd *cobra.Command, args []string) error { if len(args) != 1 { - fmt.Fprintf(os.Stderr, "expected exactly 1 argument, got %d", len(args)) - os.Exit(128) + return fmt.Errorf("expected exactly 1 argument, got %d", len(args)) } cli := client.New(uri, requestTimeout) info, values, err := cli.Info(args[0]) diff --git a/cmd/spacescli/cmd/lifeline.go b/cmd/spacescli/cmd/lifeline.go index 0bf2c3a3..77014743 100644 --- a/cmd/spacescli/cmd/lifeline.go +++ b/cmd/spacescli/cmd/lifeline.go @@ -6,7 +6,6 @@ package cmd import ( "context" "fmt" - "os" "strconv" "strings" @@ -31,8 +30,10 @@ func lifelineFunc(cmd *cobra.Command, args []string) error { return err } - space, units := getLifelineOp(args) - cli := client.New(uri, requestTimeout) + space, units, err := getLifelineOp(args) + if err != nil { + return err + } utx := &chain.LifelineTx{ BaseTx: &chain.BaseTx{}, @@ -40,6 +41,7 @@ func lifelineFunc(cmd *cobra.Command, args []string) error { Units: units, } + cli := client.New(uri, requestTimeout) opts := []client.OpOption{client.WithPollTx()} if verbose { opts = append(opts, client.WithInfo(space)) @@ -53,10 +55,9 @@ func lifelineFunc(cmd *cobra.Command, args []string) error { return nil } -func getLifelineOp(args []string) (space string, units uint64) { +func getLifelineOp(args []string) (space string, units uint64, err error) { if len(args) != 2 { - fmt.Fprintf(os.Stderr, "expected exactly 1 argument, got %d", len(args)) - os.Exit(128) + return "", 0, fmt.Errorf("expected exactly 1 argument, got %d", len(args)) } space = args[0] @@ -65,15 +66,13 @@ func getLifelineOp(args []string) (space string, units uint64) { // check here first before parsing in case "space" is empty if err := parser.CheckContents(space); err != nil { - fmt.Fprintf(os.Stderr, "failed to verify space %v", err) - os.Exit(128) + return "", 0, fmt.Errorf("%w: failed to verify space", err) } - units, err := strconv.ParseUint(args[1], 10, 64) + units, err = strconv.ParseUint(args[1], 10, 64) if err != nil { - fmt.Fprintf(os.Stderr, "failed to parse units %v", err) - os.Exit(128) + return "", 0, fmt.Errorf("%w: failed to parse units", err) } - return space, units + return space, units, nil } diff --git a/cmd/spacescli/cmd/move.go b/cmd/spacescli/cmd/move.go index fd6d9a16..b436f888 100644 --- a/cmd/spacescli/cmd/move.go +++ b/cmd/spacescli/cmd/move.go @@ -6,7 +6,6 @@ package cmd import ( "context" "fmt" - "os" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" @@ -30,8 +29,10 @@ func moveFunc(cmd *cobra.Command, args []string) error { return err } - to, space := getMoveOp(args) - cli := client.New(uri, requestTimeout) + to, space, err := getMoveOp(args) + if err != nil { + return err + } utx := &chain.MoveTx{ BaseTx: &chain.BaseTx{}, @@ -39,6 +40,7 @@ func moveFunc(cmd *cobra.Command, args []string) error { Space: space, } + cli := client.New(uri, requestTimeout) opts := []client.OpOption{client.WithPollTx()} if verbose { opts = append(opts, client.WithInfo(space)) @@ -52,16 +54,14 @@ func moveFunc(cmd *cobra.Command, args []string) error { return nil } -func getMoveOp(args []string) (to common.Address, space string) { +func getMoveOp(args []string) (to common.Address, space string, err error) { if len(args) != 2 { - fmt.Fprintf(os.Stderr, "expected exactly 2 arguments, got %d", len(args)) - os.Exit(128) + return common.Address{}, "", fmt.Errorf("expected exactly 2 arguments, got %d", len(args)) } addr := common.HexToAddress(args[0]) if err := parser.CheckContents(args[1]); err != nil { - fmt.Fprintf(os.Stderr, "failed to parse space %v", err) - os.Exit(128) + return common.Address{}, "", fmt.Errorf("%w: failed to parse space", err) } - return addr, args[1] + return addr, args[1], nil } diff --git a/cmd/spacescli/cmd/set.go b/cmd/spacescli/cmd/set.go index 02c1a366..26385159 100644 --- a/cmd/spacescli/cmd/set.go +++ b/cmd/spacescli/cmd/set.go @@ -6,7 +6,6 @@ package cmd import ( "context" "fmt" - "os" "github.com/ethereum/go-ethereum/crypto" "github.com/fatih/color" @@ -65,8 +64,10 @@ func setFunc(cmd *cobra.Command, args []string) error { return err } - space, key, val := getSetOp(args) - cli := client.New(uri, requestTimeout) + space, key, val, err := getSetOp(args) + if err != nil { + return err + } utx := &chain.SetTx{ BaseTx: &chain.BaseTx{}, @@ -75,6 +76,7 @@ func setFunc(cmd *cobra.Command, args []string) error { Value: val, } + cli := client.New(uri, requestTimeout) opts := []client.OpOption{client.WithPollTx()} if verbose { opts = append(opts, client.WithInfo(space)) @@ -88,23 +90,19 @@ func setFunc(cmd *cobra.Command, args []string) error { return nil } -func getSetOp(args []string) (space string, key string, val []byte) { +func getSetOp(args []string) (space string, key string, val []byte, err error) { if len(args) != 2 { - fmt.Fprintf(os.Stderr, "expected exactly 2 arguments, got %d", len(args)) - os.Exit(128) + return "", "", nil, fmt.Errorf("expected exactly 2 arguments, got %d", len(args)) } // [space/key] == "foo/bar" spaceKey := args[0] - var err error space, key, err = parser.ResolvePath(spaceKey) if err != nil { - fmt.Fprintf(os.Stderr, "failed to parse space %v", err) - os.Exit(128) + return "", "", nil, fmt.Errorf("%w: failed to parse space", err) } val = []byte(args[1]) - - return space, key, val + return space, key, val, err } diff --git a/cmd/spacescli/cmd/transfer.go b/cmd/spacescli/cmd/transfer.go index 7d07517f..da30f54f 100644 --- a/cmd/spacescli/cmd/transfer.go +++ b/cmd/spacescli/cmd/transfer.go @@ -6,7 +6,6 @@ package cmd import ( "context" "fmt" - "os" "strconv" "github.com/ethereum/go-ethereum/common" @@ -30,8 +29,10 @@ func transferFunc(cmd *cobra.Command, args []string) error { return err } - to, units := getTransferOp(args) - cli := client.New(uri, requestTimeout) + to, units, err := getTransferOp(args) + if err != nil { + return err + } utx := &chain.TransferTx{ BaseTx: &chain.BaseTx{}, @@ -39,6 +40,7 @@ func transferFunc(cmd *cobra.Command, args []string) error { Units: units, } + cli := client.New(uri, requestTimeout) opts := []client.OpOption{client.WithPollTx()} if verbose { opts = append(opts, client.WithBalance()) @@ -51,17 +53,15 @@ func transferFunc(cmd *cobra.Command, args []string) error { return nil } -func getTransferOp(args []string) (to common.Address, units uint64) { +func getTransferOp(args []string) (to common.Address, units uint64, err error) { if len(args) != 2 { - fmt.Fprintf(os.Stderr, "expected exactly 2 arguments, got %d", len(args)) - os.Exit(128) + return common.Address{}, 0, fmt.Errorf("expected exactly 2 arguments, got %d", len(args)) } addr := common.HexToAddress(args[0]) - units, err := strconv.ParseUint(args[1], 10, 64) + units, err = strconv.ParseUint(args[1], 10, 64) if err != nil { - fmt.Fprintf(os.Stderr, "failed to parse units %v", err) - os.Exit(128) + return common.Address{}, 0, fmt.Errorf("%w: failed to parse units", err) } - return addr, units + return addr, units, nil } From cc75c8f1a6d78e7b07692da1a27dac18c6600ff7 Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Tue, 18 Jan 2022 22:57:51 -0800 Subject: [PATCH 11/15] fix integration test --- tests/integration/integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 5acf70b8..550568f7 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -356,7 +356,7 @@ var _ = ginkgo.Describe("Tx Types", func() { pf, values, err := instances[0].cli.Info(space) gomega.Ω(err).To(gomega.BeNil()) gomega.Ω(pf).NotTo(gomega.BeNil()) - gomega.Ω(pf.Units).To(gomega.Equal(uint64(1))) + gomega.Ω(pf.Units).To(gomega.Equal(uint64(100))) gomega.Ω(pf.Owner).To(gomega.Equal(sender)) gomega.Ω(len(values)).To(gomega.Equal(0)) }) From c25bb5ecfdaccee88d7baaf6ef80a3bbc671c2d4 Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Tue, 18 Jan 2022 22:58:51 -0800 Subject: [PATCH 12/15] README nits --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d7b585e3..87a6f471 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ You could build... * Twitter Feed-like ## How it Works -### Flow +### Action Types #### Claim ##### Community support From 6f162ce8489da53cca5887d3b7f795c9099ae564 Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Tue, 18 Jan 2022 23:10:38 -0800 Subject: [PATCH 13/15] fix e2e test --- tests/e2e/e2e_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 0d98e0c8..25dee6db 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -166,7 +166,7 @@ var _ = ginkgo.Describe("[Claim/SetTx]", func() { color.Blue("checking space on %q", inst.uri) pf, _, err := inst.cli.Info(space) gomega.Ω(err).To(gomega.BeNil()) - gomega.Ω(pf.Units).To(gomega.Equal(uint64(1))) + gomega.Ω(pf.Units).To(gomega.Equal(uint64(100))) gomega.Ω(pf.Owner).To(gomega.Equal(sender)) } }) @@ -349,7 +349,7 @@ var _ = ginkgo.Describe("[Claim/SetTx]", func() { color.Blue("checking space on %q", inst.uri) pf, _, err := inst.cli.Info(space) gomega.Ω(err).To(gomega.BeNil()) - gomega.Ω(pf.Units).To(gomega.Equal(uint64(1))) + gomega.Ω(pf.Units).To(gomega.Equal(uint64(100))) gomega.Ω(pf.Owner).To(gomega.Equal(sender)) } }) From 8560b187d9a54d2e434424ccd0924074e212c215 Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Tue, 18 Jan 2022 23:17:10 -0800 Subject: [PATCH 14/15] update README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 87a6f471..282bd70f 100644 --- a/README.md +++ b/README.md @@ -421,6 +421,8 @@ To build the VM, run `VM=true ./scripts/build.sh`. Put spacesvm binary in plugins dir Add subnet-id to whitelisted-subnets +TODO: set bootstrap nodes + Here is an example config file: --network-id=fuji From f9efe2a5647fcd933a550ecc518febf3ff5d33a2 Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Tue, 18 Jan 2022 23:24:36 -0800 Subject: [PATCH 15/15] more e2e errors --- tests/e2e/e2e_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 25dee6db..c4f2f31a 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -203,7 +203,7 @@ var _ = ginkgo.Describe("[Claim/SetTx]", func() { color.Blue("checking space on %q", inst.uri) pf, _, err := inst.cli.Info(space) gomega.Ω(err).To(gomega.BeNil()) - gomega.Ω(pf.Units).To(gomega.Equal(uint64(2))) + gomega.Ω(pf.Units).To(gomega.Equal(uint64(101))) gomega.Ω(pf.Owner).To(gomega.Equal(sender)) } }) @@ -253,7 +253,7 @@ var _ = ginkgo.Describe("[Claim/SetTx]", func() { color.Blue("checking space on %q", inst.uri) pf, _, err := inst.cli.Info(space) gomega.Ω(err).To(gomega.BeNil()) - gomega.Ω(pf.Units).To(gomega.Equal(uint64(22))) + gomega.Ω(pf.Units).To(gomega.Equal(uint64(121))) gomega.Ω(pf.Owner).To(gomega.Equal(sender)) } }) @@ -301,7 +301,7 @@ var _ = ginkgo.Describe("[Claim/SetTx]", func() { color.Blue("checking space on %q", inst.uri) pf, _, err := inst.cli.Info(space) gomega.Ω(err).To(gomega.BeNil()) - gomega.Ω(pf.Units).To(gomega.Equal(uint64(1))) + gomega.Ω(pf.Units).To(gomega.Equal(uint64(100))) gomega.Ω(pf.Owner).To(gomega.Equal(sender)) } }) @@ -384,7 +384,7 @@ var _ = ginkgo.Describe("[Claim/SetTx]", func() { color.Blue("checking space on %q", inst.uri) pf, _, err := inst.cli.Info(space) gomega.Ω(err).To(gomega.BeNil()) - gomega.Ω(pf.Units).To(gomega.Equal(uint64(2))) + gomega.Ω(pf.Units).To(gomega.Equal(uint64(101))) gomega.Ω(pf.Owner).To(gomega.Equal(sender)) } }) @@ -432,7 +432,7 @@ var _ = ginkgo.Describe("[Claim/SetTx]", func() { color.Blue("checking space on %q", inst.uri) pf, _, err := inst.cli.Info(space) gomega.Ω(err).To(gomega.BeNil()) - gomega.Ω(pf.Units).To(gomega.Equal(uint64(22))) + gomega.Ω(pf.Units).To(gomega.Equal(uint64(121))) gomega.Ω(pf.Owner).To(gomega.Equal(sender)) } }) @@ -478,7 +478,7 @@ var _ = ginkgo.Describe("[Claim/SetTx]", func() { color.Blue("checking space on %q", inst.uri) pf, _, err := inst.cli.Info(space) gomega.Ω(err).To(gomega.BeNil()) - gomega.Ω(pf.Units).To(gomega.Equal(uint64(1))) + gomega.Ω(pf.Units).To(gomega.Equal(uint64(100))) gomega.Ω(pf.Owner).To(gomega.Equal(sender)) } })