Skip to content

Commit

Permalink
save confirmations sigs into app state (#102)
Browse files Browse the repository at this point in the history
* starter

* testing client with ganache

* Squashed 'contracts/' content from commit ab4fd0e

git-subtree-dir: contracts
git-subtree-split: ab4fd0e

* contract wrappers and bindings

* subscribed to deposits/exists. Some tests

* added wrappers to the contracts folder

* Squashed 'contracts/' changes from ab4fd0e..dc28e6a

dc28e6a [Audit Milestone] No rootchain finality checks (#79)
b7ddf5c Simple Merkle Tree (#77)
62a9462 position in the exit struct. removed helpers (#78)

git-subtree-dir: contracts
git-subtree-split: dc28e6a

* MOAR PROGRESS

* papusa

* gopkg fix

* added clean to npm script. temp removed wrappers

* Squashed 'contracts/' changes from dc28e6a..4fcc49e

4fcc49e doc typo (#83)
088adc7 [Audit milestone] Fee withdrawal for validators  (#80)
bc1b116 Finalize Revert (#82)

git-subtree-dir: contracts
git-subtree-split: 4fcc49e

* updated wrappers

* updated config for block finality and eth priv key default directory

* Squashed 'contracts/' changes from 4fcc49e..1b58d54

1b58d54 added eth blocknum to the deposit struct (#85)

git-subtree-dir: contracts
git-subtree-split: 1b58d54

* deposits with finality checks

* merge conflicts

* removed err from HasTxBeenExited

* refactors and added tests. Fixed deposit encoding/decoding

* typo

* debugging

* changed rlp to json

* save progress

* save confirmations sigs into app state

* added check for fee amount

* added confirmation signatures to prove command

* ante

* adjusted names, load latest version

* remove prints

* merge conflicts

* merge conflicts for contracts

* more merge conflicts

* conflict

* undo merges that didnt delete

* last of conflicts

* fixed build and test issues

* refactored app tests, works around genesis deposit issue
  • Loading branch information
colin-axner authored Dec 20, 2018
1 parent b316701 commit 623fa0c
Show file tree
Hide file tree
Showing 18 changed files with 314 additions and 438 deletions.
43 changes: 24 additions & 19 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package app

import (
"fmt"
"crypto/ecdsa"
"encoding/binary"
"encoding/json"
auth "github.com/FourthState/plasma-mvp-sidechain/auth"
"github.com/FourthState/plasma-mvp-sidechain/eth"
"github.com/FourthState/plasma-mvp-sidechain/types"
"github.com/FourthState/plasma-mvp-sidechain/x/metadata"
"github.com/FourthState/plasma-mvp-sidechain/utils"
"github.com/FourthState/plasma-mvp-sidechain/x/kvstore"
"github.com/FourthState/plasma-mvp-sidechain/x/utxo"
abci "github.com/tendermint/tendermint/abci/types"
"io"
Expand Down Expand Up @@ -42,12 +43,12 @@ type ChildChain struct {
// keys to access the substores
capKeyMainStore *sdk.KVStoreKey

capKeyMetadataStore *sdk.KVStoreKey
capKeyPlasmaStore *sdk.KVStoreKey

// Manage addition and deletion of utxo's
utxoMapper utxo.Mapper

metadataMapper metadata.MetadataMapper
plasmaStore kvstore.KVStore

/* Validator Information */
isValidator bool
Expand All @@ -65,10 +66,10 @@ type ChildChain struct {
nodeURL string

// Minimum Fee a validator is willing to accept
min_fees uint64
minFees uint64

// Number of blocks required for a submitted block to be considered final
block_finality uint64
blockFinality uint64

ethConnection *eth.Plasma
}
Expand All @@ -80,12 +81,12 @@ func NewChildChain(logger log.Logger, db dbm.DB, traceStore io.Writer, options .
bapp.SetCommitMultiStoreTracer(traceStore)

var app = &ChildChain{
BaseApp: bapp,
cdc: cdc,
txIndex: 0,
feeAmount: 0,
capKeyMainStore: sdk.NewKVStoreKey("main"),
capKeyMetadataStore: sdk.NewKVStoreKey("metadata"),
BaseApp: bapp,
cdc: cdc,
txIndex: 0,
feeAmount: 0,
capKeyMainStore: sdk.NewKVStoreKey("main"),
capKeyPlasmaStore: sdk.NewKVStoreKey("plasma"),
}

for _, option := range options {
Expand All @@ -98,40 +99,43 @@ func NewChildChain(logger log.Logger, db dbm.DB, traceStore io.Writer, options .
cdc,
)

app.metadataMapper = metadata.NewMetadataMapper(
app.capKeyMetadataStore,
app.plasmaStore = kvstore.NewKVStore(
app.capKeyPlasmaStore,
)

app.Router().
AddRoute("spend", utxo.NewSpendHandler(app.utxoMapper, app.nextPosition))

app.MountStoresIAVL(app.capKeyMainStore)
app.MountStoresIAVL(app.capKeyMetadataStore)
app.MountStoresIAVL(app.capKeyPlasmaStore)

app.SetInitChainer(app.initChainer)
app.SetEndBlocker(app.endBlocker)

// Set Ethereum connection
fmt.Println(app.nodeURL)
client, err := eth.InitEthConn(app.nodeURL, bapp.Logger)
if err != nil {
panic(err)
}

plasmaClient, err := eth.InitPlasma(app.rootchain.Hex(), app.validatorPrivKey, client, app.BaseApp.Logger, app.block_finality, app.isValidator)
plasmaClient, err := eth.InitPlasma(app.rootchain, app.validatorPrivKey, client, app.BaseApp.Logger, app.blockFinality)
if err != nil {
panic(err)
}

app.ethConnection = plasmaClient

// NOTE: type AnteHandler func(ctx Context, tx Tx) (newCtx Context, result Result, abort bool)
app.SetAnteHandler(auth.NewAnteHandler(app.utxoMapper, app.metadataMapper, app.feeUpdater, app.ethConnection))
app.SetAnteHandler(auth.NewAnteHandler(app.utxoMapper, app.plasmaStore, app.feeUpdater, app.ethConnection))

err = app.LoadLatestVersion(app.capKeyMainStore)
if err != nil {
cmn.Exit(err.Error())
}
err = app.LoadLatestVersion(app.capKeyPlasmaStore)
if err != nil {
cmn.Exit(err.Error())
}

return app
}
Expand Down Expand Up @@ -180,9 +184,10 @@ func (app *ChildChain) endBlocker(ctx sdk.Context, req abci.RequestEndBlock) abc

blknumKey := make([]byte, binary.MaxVarintLen64)
binary.PutUvarint(blknumKey, uint64(ctx.BlockHeight()))
key := append(utils.RootHashPrefix, blknumKey...)

if ctx.BlockHeader().DataHash != nil {
app.metadataMapper.StoreMetadata(ctx, blknumKey, ctx.BlockHeader().DataHash)
app.plasmaStore.Set(ctx, key, ctx.BlockHeader().DataHash)
}
return abci.ResponseEndBlock{}
}
Expand Down
Loading

0 comments on commit 623fa0c

Please sign in to comment.