Skip to content

Commit

Permalink
updated to latest everything. booyeh
Browse files Browse the repository at this point in the history
  • Loading branch information
ebuchman committed Dec 9, 2017
1 parent 4088424 commit 6522910
Show file tree
Hide file tree
Showing 64 changed files with 202 additions and 201 deletions.
8 changes: 4 additions & 4 deletions app/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type StoreApp struct {
pending []*abci.Validator

// height is last committed block, DeliverTx is the next one
height uint64
height int64

logger log.Logger
}
Expand Down Expand Up @@ -99,12 +99,12 @@ func (app *StoreApp) Check() sm.SimpleDB {

// CommittedHeight gets the last block height committed
// to the db
func (app *StoreApp) CommittedHeight() uint64 {
func (app *StoreApp) CommittedHeight() int64 {
return app.height
}

// WorkingHeight gets the current block we are writing
func (app *StoreApp) WorkingHeight() uint64 {
func (app *StoreApp) WorkingHeight() int64 {
return app.height + 1
}

Expand Down Expand Up @@ -243,7 +243,7 @@ func pubKeyIndex(val *abci.Validator, list []*abci.Validator) int {
return -1
}

func loadState(dbName string, cacheSize int, historySize uint64) (*sm.State, error) {
func loadState(dbName string, cacheSize int, historySize int64) (*sm.State, error) {
// memory backed case, just for testing
if dbName == "" {
tree := iavl.NewVersionedTree(0, dbm.NewMemDB())
Expand Down
4 changes: 2 additions & 2 deletions app/val_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
//-----------------------------------
// Test cases start here

func randPower() uint64 {
return uint64(cmn.RandInt()%50 + 60)
func randPower() int64 {
return int64(cmn.RandInt()%50 + 60)
}

func makeVal() *abci.Validator {
Expand Down
2 changes: 1 addition & 1 deletion client/commands/commits/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func exportCommit(cmd *cobra.Command, args []string) error {

// load the seed as specified
trust, _ := commands.GetProviders()
h := viper.GetInt(heightFlag)
h := int64(viper.GetInt(heightFlag))
hash := viper.GetString(hashFlag)
fc, err := loadCommit(trust, h, hash, "")
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions client/commands/commits/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func init() {
RootCmd.AddCommand(showCmd)
}

func loadCommit(p lite.Provider, h int, hash, file string) (fc lite.FullCommit, err error) {
func loadCommit(p lite.Provider, h int64, hash, file string) (fc lite.FullCommit, err error) {
// load the commit from the proper place
if h != 0 {
fc, err = p.GetByHeight(h)
Expand All @@ -59,7 +59,7 @@ func loadCommit(p lite.Provider, h int, hash, file string) (fc lite.FullCommit,
func showCommit(cmd *cobra.Command, args []string) error {
trust, _ := commands.GetProviders()

h := viper.GetInt(heightFlag)
h := int64(viper.GetInt(heightFlag))
hash := viper.GetString(hashFlag)
file := viper.GetString(fileFlag)
fc, err := loadCommit(trust, h, hash, file)
Expand Down
2 changes: 1 addition & 1 deletion client/commands/commits/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func updateCommit(cmd *cobra.Command, args []string) error {
return err
}

h := viper.GetInt(heightFlag)
h := int64(viper.GetInt(heightFlag))
var fc lite.FullCommit
if h <= 0 {
// get the lastest from our source
Expand Down
23 changes: 13 additions & 10 deletions client/commands/query/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
// It will try to get the proof for the given key. If it is successful,
// it will return the height and also unserialize proof.Data into the data
// argument (so pass in a pointer to the appropriate struct)
func GetParsed(key []byte, data interface{}, height int, prove bool) (uint64, error) {
func GetParsed(key []byte, data interface{}, height int64, prove bool) (int64, error) {
bs, h, err := Get(key, height, prove)
if err != nil {
return 0, err
Expand All @@ -47,16 +47,19 @@ func GetParsed(key []byte, data interface{}, height int, prove bool) (uint64, er
// we just repeat whatever any (potentially malicious) node gives us.
// Only use that if you are running the full node yourself,
// and it is localhost or you have a secure connection (not HTTP)
func Get(key []byte, height int, prove bool) (data.Bytes, uint64, error) {
func Get(key []byte, height int64, prove bool) (data.Bytes, int64, error) {
if height < 0 {
return nil, 0, fmt.Errorf("Height cannot be negative")
}

if !prove {
node := commands.GetNode()
resp, err := node.ABCIQueryWithOptions("/key", key,
rpcclient.ABCIQueryOptions{Trusted: true, Height: uint64(height)})
return data.Bytes(resp.Value), resp.Height, err
rpcclient.ABCIQueryOptions{Trusted: true, Height: int64(height)})
if resp == nil {
return nil, height, err
}
return data.Bytes(resp.Response.Value), resp.Response.Height, err
}
val, h, _, err := GetWithProof(key, height)
return val, h, err
Expand All @@ -65,7 +68,7 @@ func Get(key []byte, height int, prove bool) (data.Bytes, uint64, error) {
// GetWithProof returns the values stored under a given key at the named
// height as in Get. Additionally, it will return a validated merkle
// proof for the key-value pair if it exists, and all checks pass.
func GetWithProof(key []byte, height int) (data.Bytes, uint64, iavl.KeyProof, error) {
func GetWithProof(key []byte, height int64) (data.Bytes, int64, iavl.KeyProof, error) {
node := commands.GetNode()
cert, err := commands.GetCertifier()
if err != nil {
Expand Down Expand Up @@ -93,19 +96,19 @@ func ParseHexKey(args []string, argname string) ([]byte, error) {
}

// GetHeight reads the viper config for the query height
func GetHeight() int {
return viper.GetInt(FlagHeight)
func GetHeight() int64 {
return int64(viper.GetInt(FlagHeight))
}

type proof struct {
Height uint64 `json:"height"`
Height int64 `json:"height"`
Data interface{} `json:"data"`
}

// FoutputProof writes the output of wrapping height and info
// in the form {"data": <the_data>, "height": <the_height>}
// to the provider io.Writer
func FoutputProof(w io.Writer, v interface{}, height uint64) error {
func FoutputProof(w io.Writer, v interface{}, height int64) error {
wrap := &proof{height, v}
blob, err := data.ToJSON(wrap)
if err != nil {
Expand All @@ -118,6 +121,6 @@ func FoutputProof(w io.Writer, v interface{}, height uint64) error {
// OutputProof prints the proof to stdout
// reuse this for printing proofs and we should enhance this for text/json,
// better presentation of height
func OutputProof(data interface{}, height uint64) error {
func OutputProof(data interface{}, height int64) error {
return FoutputProof(os.Stdout, data, height)
}
2 changes: 1 addition & 1 deletion client/commands/query/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func txQueryCmd(cmd *cobra.Command, args []string) error {
}

// showTx parses anything that was previously registered as sdk.Tx
func showTx(h uint64, tx types.Tx) error {
func showTx(h int64, tx types.Tx) error {
var info sdk.Tx
err := wire.ReadBinaryBytes(tx, &info)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions client/commands/rpc/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ func init() {

func runWait(cmd *cobra.Command, args []string) error {
c := commands.GetNode()
h := viper.GetInt(FlagHeight)
h := int64(viper.GetInt(FlagHeight))
if h == -1 {
// read from delta
d := viper.GetInt(FlagDelta)
d := int64(viper.GetInt(FlagDelta))
if d == -1 {
return errors.New("Must set --height or --delta")
}
Expand Down
8 changes: 4 additions & 4 deletions client/commands/rpc/secure.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func runBlock(cmd *cobra.Command, args []string) error {
return err
}

h := viper.GetInt(FlagHeight)
h := int64(viper.GetInt(FlagHeight))
block, err := c.Block(&h)
if err != nil {
return err
Expand All @@ -46,7 +46,7 @@ func runCommit(cmd *cobra.Command, args []string) error {
return err
}

h := viper.GetInt(FlagHeight)
h := int64(viper.GetInt(FlagHeight))
commit, err := c.Commit(&h)
if err != nil {
return err
Expand All @@ -66,8 +66,8 @@ func runHeaders(cmd *cobra.Command, args []string) error {
return err
}

min := viper.GetInt(FlagMin)
max := viper.GetInt(FlagMax)
min := int64(viper.GetInt(FlagMin))
max := int64(viper.GetInt(FlagMax))
headers, err := c.BlockchainInfo(min, max)
if err != nil {
return err
Expand Down
23 changes: 10 additions & 13 deletions client/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
// If there is any error in checking, returns an error.
// If val is non-empty, proof should be KeyExistsProof
// If val is empty, proof should be KeyMissingProof
func GetWithProof(key []byte, reqHeight int, node rpcclient.Client,
func GetWithProof(key []byte, reqHeight int64, node rpcclient.Client,
cert lite.Certifier) (
val data.Bytes, height uint64, proof iavl.KeyProof, err error) {
val data.Bytes, height int64, proof iavl.KeyProof, err error) {

if reqHeight < 0 {
err = errors.Errorf("Height cannot be negative")
Expand All @@ -33,7 +33,7 @@ func GetWithProof(key []byte, reqHeight int, node rpcclient.Client,
node, cert)
if _resp != nil {
resp := _resp.Response
val, height = resp.Value, uint64(resp.Height)
val, height = resp.Value, resp.Height
}
return val, height, proof, err
}
Expand Down Expand Up @@ -79,7 +79,7 @@ func GetWithProofOptions(path string, key []byte, opts rpcclient.ABCIQueryOption
if err != nil {
return nil, nil, errors.Wrap(err, "Couldn't verify proof")
}
return resp, eproof, nil
return &ctypes.ResultABCIQuery{resp}, eproof, nil
}

// The key wasn't found, construct a proof of non-existence.
Expand All @@ -93,30 +93,27 @@ func GetWithProofOptions(path string, key []byte, opts rpcclient.ABCIQueryOption
if err != nil {
return nil, nil, errors.Wrap(err, "Couldn't verify proof")
}
return resp, aproof, ErrNoData()
return &ctypes.ResultABCIQuery{resp}, aproof, ErrNoData()
}

// GetCertifiedCommit gets the signed header for a given height
// and certifies it. Returns error if unable to get a proven header.
func GetCertifiedCommit(h uint64, node rpcclient.Client,
func GetCertifiedCommit(h int64, node rpcclient.Client,
cert lite.Certifier) (empty lite.Commit, err error) {

// TODO: please standardize all int types
ih := int(h)

// FIXME: cannot use cert.GetByHeight for now, as it also requires
// Validators and will fail on querying tendermint for non-current height.
// When this is supported, we should use it instead...
rpcclient.WaitForHeight(node, ih, nil)
cresp, err := node.Commit(&ih)
rpcclient.WaitForHeight(node, h, nil)
cresp, err := node.Commit(&h)
if err != nil {
return
}
commit := client.CommitFromResult(cresp)

// validate downloaded checkpoint with our request and trust store.
if commit.Height() != ih {
return empty, certerr.ErrHeightMismatch(ih, commit.Height())
if commit.Height() != h {
return empty, certerr.ErrHeightMismatch(h, commit.Height())
}
err = cert.Certify(commit)
return commit, nil
Expand Down
2 changes: 1 addition & 1 deletion client/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestAppProofs(t *testing.T) {
bs, height, proof, err = GetWithProof(k, brh, cl, cert)
require.NoError(err, "%+v", err)
require.NotNil(proof)
require.True(height >= uint64(latest.Header.Height))
require.True(height >= int64(latest.Header.Height))

// Alexis there is a bug here, somehow the above code gives us rootHash = nil
// and proof.Verify doesn't care, while proofNotExists.Verify fails.
Expand Down
8 changes: 4 additions & 4 deletions client/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (w Wrapper) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
if !prove || err != nil {
return res, err
}
h := uint64(res.Height)
h := int64(res.Height)
check, err := GetCertifiedCommit(h, w.Client, w.cert)
if err != nil {
return res, err
Expand All @@ -64,7 +64,7 @@ func (w Wrapper) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
// Rather expensive.
//
// TODO: optimize this if used for anything needing performance
func (w Wrapper) BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchainInfo, error) {
func (w Wrapper) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) {
r, err := w.Client.BlockchainInfo(minHeight, maxHeight)
if err != nil {
return nil, err
Expand All @@ -88,7 +88,7 @@ func (w Wrapper) BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockch
}

// Block returns an entire block and verifies all signatures
func (w Wrapper) Block(height *int) (*ctypes.ResultBlock, error) {
func (w Wrapper) Block(height *int64) (*ctypes.ResultBlock, error) {
r, err := w.Client.Block(height)
if err != nil {
return nil, err
Expand All @@ -115,7 +115,7 @@ func (w Wrapper) Block(height *int) (*ctypes.ResultBlock, error) {
// Commit downloads the Commit and certifies it with the lite.
//
// This is the foundation for all other verification in this module
func (w Wrapper) Commit(height *int) (*ctypes.ResultCommit, error) {
func (w Wrapper) Commit(height *int64) (*ctypes.ResultCommit, error) {
rpcclient.WaitForHeight(w.Client, *height, nil)
r, err := w.Client.Commit(height)
// if we got it, then certify it
Expand Down
2 changes: 1 addition & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type Context interface {
IsParent(ctx Context) bool
Reset() Context
ChainID() string
BlockHeight() uint64
BlockHeight() int64
}

//////////////////////////////// Sort Interface
Expand Down
15 changes: 15 additions & 0 deletions errors/code.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package errors

const (
defaultErrCode uint32 = 0x1

CodeTypeInternalErr uint32 = 0
CodeTypeEncodingErr uint32 = 1
CodeTypeUnauthorized uint32 = 2
CodeTypeUnknownRequest uint32 = 3
CodeTypeUnknownAddress uint32 = 4
CodeTypeBaseUnknownAddress uint32 = 4 // lol fuck it
CodeTypeBadNonce uint32 = 5
CodeTypeBaseInvalidInput uint32 = 20
CodeTypeBaseInvalidOutput uint32 = 21
)
Loading

0 comments on commit 6522910

Please sign in to comment.