Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: Colin/store #153

Merged
merged 57 commits into from
Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
148cb24
kvstore is a private member
hamdiallam May 8, 2019
c8126e7
query routes for utxo
hamdiallam May 8, 2019
05813cf
Merge branch 'hamdi/query' of github.com:FourthState/plasma-mvp-sidec…
colin-axner May 8, 2019
5f8b0f3
message when no utxos are available
hamdiallam May 8, 2019
7e1a4b9
change to deposit, block, and tx store
colin-axner May 9, 2019
1736b1e
block querier. store utxo already satisfies rlp interface
hamdiallam May 10, 2019
960027b
adjusting inputs outputs to be variable, updated app
colin-axner May 10, 2019
ffc5ad1
file rename. remove resp objects
hamdiallam May 10, 2019
87501a1
refactored plasma/, updated tests
colin-axner May 10, 2019
c4358e2
updated msgs/
colin-axner May 10, 2019
0943e9c
refactored handlers/ still need to update tests
colin-axner May 10, 2019
4fb3b12
merge with hamdis branch
colin-axner May 10, 2019
65a44f0
Fix build errors and test issue in store/
colin-axner May 10, 2019
e8e5418
added tests for deposit and block stores
colin-axner May 11, 2019
4a9f92a
added tests to store, failing on deep equal
colin-axner May 11, 2019
591b3ac
wip rest server
hamdiallam May 11, 2019
db089bf
revert spend to original functionality
hamdiallam May 11, 2019
f22b65c
store test bug fix
colin-axner May 13, 2019
fb1fd2d
merge rest branch
colin-axner May 13, 2019
e79b8e5
added account, updated querier
colin-axner May 14, 2019
714b0ed
commit current work, prep to merge deposit/tx stores
colin-axner May 15, 2019
5c790db
updated output store
colin-axner May 15, 2019
b8582c3
deleted depositStore, fixed bugs in outputStore
colin-axner May 15, 2019
9ea2295
refactored handlers/ tests
colin-axner May 16, 2019
0691dec
added fee support to store/ with tests
colin-axner May 16, 2019
9736100
in progress work being committed for review
colin-axner May 31, 2019
0cbbb1a
query metadata about 10 blocks
hamdiallam Jun 4, 2019
7c60051
blocks query commond and likewise rest interface
hamdiallam Jun 4, 2019
9dd6071
SubmitBlock test no longer applicable
hamdiallam Jun 4, 2019
d3eed28
merged develop
hamdiallam Jun 4, 2019
28d9f2a
reflect some pr comments
colin-axner Jun 5, 2019
d0314d3
merge with hamdis
colin-axner Jun 5, 2019
a2352d2
update client query, handler err fixes
colin-axner Jun 5, 2019
c5a2ef6
some more refactor on cli
colin-axner Jun 6, 2019
62ac312
change account to wallet
colin-axner Jun 8, 2019
8094c0e
consolidate verifyandsign func
colin-axner Jun 8, 2019
0c5a538
improves output store and prove
AdityaSripal Jun 19, 2019
5fdb575
finish prove and fmt
AdityaSripal Jun 19, 2019
2714487
revert mistake
AdityaSripal Jun 19, 2019
6111e2e
merge
colin-axner Jun 26, 2019
5e6198e
some refactors on comments and pr comments
colin-axner Jun 26, 2019
7224c29
updated store querying
colin-axner Jun 30, 2019
6d93383
merge develop
colin-axner Jun 30, 2019
ba63648
fix various build/merge issue
colin-axner Jun 30, 2019
52f5487
cli fixes
colin-axner Jul 1, 2019
3010eb9
rm todos
colin-axner Jul 1, 2019
f4cce13
store fee
colin-axner Jul 1, 2019
c4436e2
validateBasic change
AdityaSripal Jul 2, 2019
278cbf3
Merge branch 'colin/store' of github.com:FourthState/plasma-mvp-sidec…
AdityaSripal Jul 2, 2019
d9926bd
fix bugs
AdityaSripal Jul 2, 2019
527d879
Apply suggestions from code review: Doc fixes
AdityaSripal Jul 2, 2019
b1eec74
address some pr comments
colin-axner Jul 2, 2019
214ae35
build fix
colin-axner Jul 3, 2019
4af2bf2
reflect my own pr comments
colin-axner Jul 5, 2019
41a5024
error update
colin-axner Jul 5, 2019
780f3ea
changelog and updated err in ante
colin-axner Jul 6, 2019
b9ecdab
update changelog
colin-axner Jul 8, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/plasmacli/eth/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func init() {

var balanceCmd = &cobra.Command{
Use: "balance <account>",
Short: "Query for balance avaliable for withdraw from rootchain",
Long: `Query for balance avaliable for withdrawal from rootchain.
Short: "Query for balance available for withdraw from rootchain",
Long: `Query for balance available for withdrawal from rootchain.

Usage:
plasmacli eth query balance <account>
Expand Down
2 changes: 1 addition & 1 deletion client/plasmacli/eth/challenge.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Usage:
var result *tm.ResultTx
result, confirmSignatures, err = getProof(owner, challengingPos)
if err != nil {
fmt.Errorf("failed to retrieve exit information: { %s }", err)
return fmt.Errorf("failed to retrieve exit information: { %s }", err)
}

txBytes = result.Tx
Expand Down
4 changes: 2 additions & 2 deletions client/plasmacli/eth/getDeposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func init() {

var getDepositsCmd = &cobra.Command{
Use: "deposit <nonce>",
Short: "Query for a deposit that occured on the rootchain",
Long: `Queries for deposits that occured on the rootchain.
Short: "Query for a deposit that occurred on the rootchain",
Long: `Queries for deposits that occurred on the rootchain.

Usage:
plasmacli eth query deposit <nonce>
Expand Down
2 changes: 1 addition & 1 deletion client/plasmacli/eth/getExits.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Usage:
}

if err := displayExits(curr, lim, addr, viper.GetBool(depositsF)); err != nil {
return fmt.Errorf("failure occured while querying exits: { %s }", err)
return fmt.Errorf("failure occurred while querying exits: { %s }", err)
}

return nil
Expand Down
58 changes: 30 additions & 28 deletions client/plasmacli/eth/prove.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"fmt"
ks "github.com/FourthState/plasma-mvp-sidechain/client/store"
"github.com/FourthState/plasma-mvp-sidechain/plasma"
"github.com/FourthState/plasma-mvp-sidechain/store"
"github.com/cosmos/cosmos-sdk/client/context"
// "github.com/FourthState/plasma-mvp-sidechain/store"
// "github.com/cosmos/cosmos-sdk/client/context"
ethcmn "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rlp"
// "github.com/ethereum/go-ethereum/rlp"
"github.com/spf13/cobra"
tm "github.com/tendermint/tendermint/rpc/core/types"
)
Expand Down Expand Up @@ -73,30 +73,32 @@ var proveCmd = &cobra.Command{

// Returns transaction results for given position
// Trusts connected full node

//TODO: REDO
func getProof(addr ethcmn.Address, position plasma.Position) (*tm.ResultTx, []byte, error) {
ctx := context.NewCLIContext().WithTrustNode(true)

// query for the output
key := append(addr.Bytes(), position.Bytes()...)
res, err := ctx.QueryStore(key, "utxo")
if err != nil {
return &tm.ResultTx{}, nil, err
}

utxo := store.UTXO{}
if err := rlp.DecodeBytes(res, &utxo); err != nil {
return &tm.ResultTx{}, nil, err
}

// query tm node for information about this tx
result, err := ctx.Client.Tx(utxo.MerkleHash, true)
if err != nil {
return &tm.ResultTx{}, nil, err
}

// Look for confirmation signatures
key = append([]byte("confirmSignature"), utxo.Position.Bytes()...)
sigs, err := ctx.QueryStore(key, "plasma")

return result, sigs, nil
/* ctx := context.NewCLIContext().WithTrustNode(true)

// query for the output
key := append(store.Key, position.Bytes()...)
res, err := ctx.QueryStore(key, "outputs")
if err != nil {
return &tm.ResultTx{}, nil, err
}

utxo := store.Output{}
if err := rlp.DecodeBytes(res, &utxo); err != nil {
return &tm.ResultTx{}, nil, err
}

// query tm node for information about this tx
result, err := ctx.Client.Tx(utxo.MerkleHash, true)
if err != nil {
return &tm.ResultTx{}, nil, err
}

// Look for confirmation signatures
key = append([]byte("confirmSignature"), utxo.Position.Bytes()...)
sigs, err := ctx.QueryStore(key, "plasma")
*/
return &tm.ResultTx{}, []byte{}, nil
}
2 changes: 1 addition & 1 deletion client/plasmacli/eth/rootchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var rootchainCmd = &cobra.Command{
Use: "rootchain",
Short: "Display rootchain contract information",
Long: `Display last committed block, total contract balance, total withdraw balance, minimum exit bond, and operator address.
Total contract balance does not include total withdraw balance. The total withdraw balance are exits that have been finalized, but not transfered yet.`,
Total contract balance does not include total withdraw balance. The total withdraw balance are exits that have been finalized, but not transferred yet.`,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, agrs []string) error {
lastCommittedBlock, err := rc.contract.LastCommittedBlock(nil)
Expand Down
4 changes: 2 additions & 2 deletions client/plasmacli/eth/withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func init() {

var withdrawCmd = &cobra.Command{
Use: "withdraw <account>",
Short: "Withdraw all avaliable funds from rootchain contract",
Long: `Withdraw all avaliable funds from the rootchain contract
Short: "Withdraw all available funds from rootchain contract",
Long: `Withdraw all available funds from the rootchain contract

Usage:
plasmacli eth withdraw <account> --gas-limit 30000`,
Expand Down
20 changes: 8 additions & 12 deletions client/plasmacli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,19 @@ func init() {
func main() {
cobra.EnableCommandSorting = false

rootCmd.Flags().String(client.FlagNode, "tcp://localhost:26657", "<host>:<port> to tendermint rpc interface for this chain")
rootCmd.PersistentFlags().String(client.FlagNode, "tcp://localhost:26657", "<host>:<port> to tendermint rpc interface for this chain")
rootCmd.PersistentFlags().Bool(client.FlagTrustNode, true, "Trust connected full node (don't verify proofs for responses)")
rootCmd.PersistentFlags().StringP(store.DirFlag, "d", homeDir, "directory for plasmacli")
if err := viper.BindPFlags(rootCmd.PersistentFlags()); err != nil {
fmt.Println(err)
}

if err := viper.BindPFlags(rootCmd.Flags()); err != nil {
viper.Set(client.FlagListenAddr, "tcp://localhost:1317")

if err := viper.BindPFlags(rootCmd.PersistentFlags()); err != nil {
fmt.Println(err)
}

viper.Set(client.FlagListenAddr, "tcp://localhost:1317")

viper.AddConfigPath(homeDir)
plasmaDir := filepath.Join(homeDir, "plasma.toml")
if _, err := os.Stat(plasmaDir); os.IsNotExist(err) {

config.WritePlasmaConfigFile(plasmaDir, config.DefaultPlasmaConfig())
}

Expand All @@ -69,18 +66,17 @@ func main() {
eth.ProveCmd(),
includeCmd,
client.LineBreak,

signCmd,
spendCmd,
client.LineBreak,

keys.KeysCmd(),
client.LineBreak,

versionCmd,
)

Execute()
}

func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package query
import (
"fmt"
ks "github.com/FourthState/plasma-mvp-sidechain/client/store"
"github.com/FourthState/plasma-mvp-sidechain/store"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/common"
"github.com/spf13/cobra"
"math/big"
)

func init() {
Expand All @@ -28,25 +26,23 @@ var balanceCmd = &cobra.Command{
return err
}

res, err := ctx.QuerySubspace(addr.Bytes(), "utxo")
total, err := Balance(ctx, addr)
if err != nil {
return err
}

total := big.NewInt(0)
utxo := store.UTXO{}
for _, pair := range res {
if err := rlp.DecodeBytes(pair.Value, &utxo); err != nil {
return err
}

if !utxo.Spent {
fmt.Printf("Position: %s , Amount: %d\n", utxo.Position, utxo.Output.Amount.Uint64())
total = total.Add(total, utxo.Output.Amount)
}
}

fmt.Printf("Total: %d\n", total.Uint64())
fmt.Printf("Address: %0x\n", addr)
fmt.Printf("Total: %s\n", total)
return nil
},
}

func Balance(ctx context.CLIContext, addr common.Address) (string, error) {
queryRoute := fmt.Sprintf("custom/utxo/balance/%s", addr.Hex())
data, err := ctx.Query(queryRoute, nil)
if err != nil {
return "", err
}

return string(data), nil
}
41 changes: 22 additions & 19 deletions client/plasmacli/query/block.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package query

import (
"encoding/json"
"fmt"
"github.com/FourthState/plasma-mvp-sidechain/plasma"
"github.com/FourthState/plasma-mvp-sidechain/store"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/ethereum/go-ethereum/rlp"
"github.com/spf13/cobra"
"math/big"
"strings"
)

Expand All @@ -20,28 +19,32 @@ var blockCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.NewCLIContext().WithTrustNode(true)
blockNum, ok := new(big.Int).SetString(strings.TrimSpace(args[0]), 10)
if !ok {
return fmt.Errorf("block number must be provided in decimal format")
}
num := strings.TrimSpace(args[0])

key := append([]byte("block::"), blockNum.Bytes()...)
data, err := ctx.QueryStore(key, "plasma")
block, err := Block(ctx, num)
if err != nil {
fmt.Println("error querying store")
return err
}
if data == nil {
return fmt.Errorf("plasma block does not exist")
}

block := plasma.Block{}
if err := rlp.DecodeBytes(data, &block); err != nil {
fmt.Println("error decoding")
return err
}
fmt.Printf("Block Header: 0x%x\n", block.Header)
fmt.Printf("Transaction Count: %d, FeeAmount: %d\n", block.TxnCount, block.FeeAmount)
fmt.Printf("Tendermint BlockHeight: %d\n", block.TMBlockHeight)

fmt.Printf("Header: %x\nTxs: %d\nFee: %d\n", block.Header, block.TxnCount, block.FeeAmount)
return nil
},
}

func Block(ctx context.CLIContext, num string) (store.Block, error) {
queryPath := fmt.Sprintf("custom/plasma/block/%s", num)
data, err := ctx.Query(queryPath, nil)
if err != nil {
return store.Block{}, err
}

var block store.Block
if err := json.Unmarshal(data, &block); err != nil {
return store.Block{}, err
}

return block, nil
}
55 changes: 30 additions & 25 deletions client/plasmacli/query/info.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package query

import (
"encoding/json"
"fmt"
"github.com/FourthState/plasma-mvp-sidechain/store"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rlp"
"github.com/spf13/cobra"
"strings"
)
Expand All @@ -20,46 +19,52 @@ var infoCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
Short: "Information on owned utxos valid and invalid",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.NewCLIContext().WithCodec(codec.New())
ctx := context.NewCLIContext()
addrStr := strings.TrimSpace(args[0])
if !common.IsHexAddress(addrStr) {
return fmt.Errorf("Invalid address provided. Please use hex format")
}
addr := common.HexToAddress(addrStr)
fmt.Printf("Querying information for 0x%x\n\n", addr)

// query for all utxos owned by this address
res, err := ctx.QuerySubspace(common.HexToAddress(addrStr).Bytes(), "utxo")
utxos, err := Info(ctx, addr)
if err != nil {
return err
}

utxo := store.UTXO{}
for i, pair := range res {
if err := rlp.DecodeBytes(pair.Value, &utxo); err != nil {
return err
}

for i, utxo := range utxos {
fmt.Printf("UTXO %d\n", i)
fmt.Printf("Position: %s, Amount: %s, Spent: %t\n", utxo.Position, utxo.Output.Amount.String(), utxo.Spent)

fmt.Printf("Position: %s, Amount: %s, Spent: %t\nSpender Hash: %s\n", utxo.Tx.Position, utxo.Output.Output.Amount.String(), utxo.Output.Spent, utxo.Output.Spender)
fmt.Printf("Transaction Hash: 0x%x\nConfirmationHash: 0x%x\n", utxo.Tx.Transaction.TxHash(), utxo.Tx.ConfirmationHash)
// print inputs if applicable
inputAddresses := utxo.InputAddresses()
positions := utxo.InputPositions()
for i, _ := range inputAddresses {
fmt.Printf("Input Owner %d, Position: %s\n", i, positions[i])
}

// print spenders if applicable
spenderAddresses := utxo.SpenderAddresses()
positions = utxo.SpenderPositions()
for i, _ := range spenderAddresses {
fmt.Printf("Spender Owner %d, Position: %s\n", i, positions[i])
positions := utxo.Tx.Transaction.InputPositions()
for i, p := range positions {
fmt.Printf("Input %d Position: %s\n", i, p)
}

fmt.Printf("End UTXO %d info\n\n", i)
}

fmt.Println()
if len(utxos) == 0 {
fmt.Println("no information available for this address")
}

return nil
},
}

func Info(ctx context.CLIContext, addr common.Address) ([]store.QueryOutput, error) {
// query for all utxos owned by this address
queryRoute := fmt.Sprintf("custom/utxo/info/%s", addr.Hex())
data, err := ctx.Query(queryRoute, nil)
if err != nil {
return nil, err
}

var utxos []store.QueryOutput
if err := json.Unmarshal(data, &utxos); err != nil {
return nil, err
}

return utxos, nil
}
Loading