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

save confirmations sigs into app state #102

Merged
merged 48 commits into from
Dec 20, 2018
Merged
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
5c9d180
starter
hamdiallam Nov 21, 2018
66de47a
testing client with ganache
hamdiallam Nov 23, 2018
48b5e14
Merge commit '1ed2e4f899f687cd0cbc28af87060fa012c4df6b' as 'contracts'
hamdiallam Nov 23, 2018
1ed2e4f
Squashed 'contracts/' content from commit ab4fd0e
hamdiallam Nov 23, 2018
5ae1fc7
contract wrappers and bindings
hamdiallam Nov 24, 2018
afa2634
subscribed to deposits/exists. Some tests
hamdiallam Nov 27, 2018
3ef8f74
added wrappers to the contracts folder
hamdiallam Nov 27, 2018
472844f
started hooking connection to app
colin-axner Dec 3, 2018
528103f
merged develop
hamdiallam Dec 3, 2018
5e12c15
Merge commit '247171637576da849a5a80ad369c91cb8d0e3a05' into rpc
hamdiallam Dec 3, 2018
2471716
Squashed 'contracts/' changes from ab4fd0e..dc28e6a
hamdiallam Dec 3, 2018
ab70ed4
MOAR PROGRESS
AdityaSripal Dec 3, 2018
c7ca091
papusa
colin-axner Dec 3, 2018
a052fd2
gopkg fix
colin-axner Dec 3, 2018
eac6e49
added clean to npm script. temp removed wrappers
hamdiallam Dec 7, 2018
582b8dc
Merge commit '6663c6816e04c161100c39f5d0e0957d36a3535b' into rpc
hamdiallam Dec 7, 2018
6663c68
Squashed 'contracts/' changes from dc28e6a..4fcc49e
hamdiallam Dec 7, 2018
c01227f
updated wrappers
hamdiallam Dec 7, 2018
7563251
updated config for block finality and eth priv key default directory
colin-axner Dec 9, 2018
8cba3b0
Squashed 'contracts/' changes from 4fcc49e..1b58d54
hamdiallam Dec 9, 2018
684b70f
Merge commit '8cba3b021c450320fbb5e5a05199467e54c70a8e' into rpc
hamdiallam Dec 9, 2018
0069dc9
deposits with finality checks
hamdiallam Dec 9, 2018
5ef281d
merge conflicts
AdityaSripal Dec 9, 2018
989e8b0
merge conflicts
AdityaSripal Dec 9, 2018
32fe39c
removed err from HasTxBeenExited
hamdiallam Dec 10, 2018
f8ea391
Merge branch 'colin/connection' of https://github.com/FourthState/pla…
AdityaSripal Dec 10, 2018
55bf4b8
refactors and added tests. Fixed deposit encoding/decoding
hamdiallam Dec 10, 2018
65c58b7
typo
hamdiallam Dec 10, 2018
3058d6b
debugging
AdityaSripal Dec 10, 2018
8678388
merge conflicts
AdityaSripal Dec 10, 2018
829b64a
changed rlp to json
hamdiallam Dec 11, 2018
e16bfbd
save progress
AdityaSripal Dec 11, 2018
975356c
fix bugs and remove print statements
AdityaSripal Dec 12, 2018
4e74968
save confirmations sigs into app state
colin-axner Dec 16, 2018
75ca7a0
added check for fee amount
colin-axner Dec 16, 2018
06f77e4
added confirmation signatures to prove command
colin-axner Dec 17, 2018
2d678b0
ante
colin-axner Dec 18, 2018
04d689c
adjusted names, load latest version
colin-axner Dec 18, 2018
9b559d2
remove prints
colin-axner Dec 18, 2018
195fc58
rebase
colin-axner Dec 20, 2018
b45694a
merge conflicts
colin-axner Dec 20, 2018
c4fb64d
merge conflicts for contracts
colin-axner Dec 20, 2018
62b6f0c
more merge conflicts
colin-axner Dec 20, 2018
95fd9f1
conflict
colin-axner Dec 20, 2018
9fd028c
undo merges that didnt delete
colin-axner Dec 20, 2018
dddede6
last of conflicts
colin-axner Dec 20, 2018
ae8b174
fixed build and test issues
colin-axner Dec 20, 2018
238b602
refactored app tests, works around genesis deposit issue
colin-axner Dec 20, 2018
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
Prev Previous commit
Next Next commit
changed rlp to json
hamdiallam committed Dec 11, 2018
commit 829b64af7988e264c8148cb81892c5a6c54ab5e5
34 changes: 8 additions & 26 deletions eth/plasma.go
Original file line number Diff line number Diff line change
@@ -3,14 +3,14 @@ package eth
import (
"context"
"crypto/ecdsa"
"encoding/json"
"errors"
rootchain "github.com/FourthState/plasma-mvp-sidechain/contracts/wrappers"
plasmaTypes "github.com/FourthState/plasma-mvp-sidechain/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/comparer"
"github.com/syndtr/goleveldb/leveldb/memdb"
@@ -115,7 +115,7 @@ func (plasma *Plasma) GetDeposit(nonce sdk.Uint) (*plasmaTypes.Deposit, error) {

var deposit plasmaTypes.Deposit
// check against the contract if the deposit is not in the cache or decoding fail
if err != nil && deserializeDeposit(data, &deposit) != nil {
if err != nil && json.Unmarshal(data, &deposit) != nil {
if plasma.memdb.Contains(key) {
plasma.logger.Info("corrupted deposit found within db")
plasma.memdb.Delete(key)
@@ -139,11 +139,7 @@ func (plasma *Plasma) GetDeposit(nonce sdk.Uint) (*plasmaTypes.Deposit, error) {
}

// save to the db
data, err = rlp.EncodeToBytes(serializedDeposit{
owner: deposit.Owner,
amount: deposit.Amount.BigInt().Bytes(),
blocknum: deposit.BlockNum.BigInt().Bytes(),
})
data, err = json.Marshal(deposit)
if err != nil {
plasma.logger.Error("error encoding deposit. will not be cached")
} else {
@@ -188,16 +184,16 @@ func watchDeposits(plasma *Plasma) {
key := prefixKey(depositPrefix, deposit.DepositNonce.Bytes())

// remove the nonce, encode, and store
val, err := rlp.EncodeToBytes(serializedDeposit{
owner: deposit.Depositor,
amount: deposit.Amount.Bytes(),
blocknum: deposit.EthBlockNum.Bytes(),
data, err := json.Marshal(plasmaTypes.Deposit{
Owner: deposit.Depositor,
Amount: sdk.NewUintFromBigInt(deposit.Amount),
BlockNum: sdk.NewUintFromBigInt(deposit.EthBlockNum),
})

if err != nil {
plasma.logger.Error("Error encoding deposit event from contract -", deposit)
} else {
plasma.memdb.Put(key, val)
plasma.memdb.Put(key, data)
}
}
}
@@ -243,17 +239,3 @@ func watchEthBlocks(plasma *Plasma, ch <-chan *types.Header) {

plasma.logger.Info("Block subscription closed.")
}

func deserializeDeposit(data []byte, deposit *plasmaTypes.Deposit) error {
var dep serializedDeposit
if err := rlp.DecodeBytes(data, &dep); err != nil {
return err
}

deposit.Owner = dep.owner
deposit.Amount = sdk.NewUintFromBigInt(new(big.Int).SetBytes(dep.amount))
deposit.Amount = sdk.NewUintFromBigInt(new(big.Int).SetBytes(dep.amount))
deposit.BlockNum = sdk.NewUintFromBigInt(new(big.Int).SetBytes(dep.blocknum))

return nil
}
29 changes: 24 additions & 5 deletions eth/plasma_test.go
Original file line number Diff line number Diff line change
@@ -64,11 +64,7 @@ func TestSubmitBlock(t *testing.T) {
logger := log.NewTMLogger(os.Stderr)
client, _ := InitEthConn(clientAddr, logger)

privKey, err := crypto.HexToECDSA(operatorPrivKey)
if err != nil {
t.Fatal("Could not convert hex private key")
}

privKey, _ := crypto.HexToECDSA(operatorPrivKey)
plasma, _ := InitPlasma(plasmaContractAddr, privKey, client, logger, 1)

blockNum, err := plasma.session.LastCommittedBlock()
@@ -99,3 +95,26 @@ func TestSubmitBlock(t *testing.T) {
t.Errorf("Mismatch in block headers.\nGot: %x\nExpected: %x", result, header)
}
}

func TestEthBlockWatching(t *testing.T) {
logger := log.NewTMLogger(os.Stderr)
client, _ := InitEthConn(clientAddr, logger)

privKey, _ := crypto.HexToECDSA(operatorPrivKey)
plasma, _ := InitPlasma(plasmaContractAddr, privKey, client, logger, 1)

lastBlockNum := plasma.ethBlockNum
t.Log(lastBlockNum)

// mine a block
err := client.rpc.Call(nil, "evm_mine")
if err != nil {
t.Fatal("Could not mine a block -", err)
}

t.Log(plasma.ethBlockNum)

if plasma.ethBlockNum.Cmp(lastBlockNum.Add(lastBlockNum, big.NewInt(1))) != 0 {
t.Error("Client did not catch the minted block and update correctly")
}
}