FourthState / plasma-mvp-sidechain

Cosmos SDK (Tendermint consensus) side-chain implementation for plasma
Apache License 2.0
112 stars 35 forks source link

R4R: Colin/store #153

Closed colin-axner closed 5 years ago

colin-axner commented 5 years ago

work in progress for updating store. My branch is off of hamdi/query so comparing it with that to see changes easier.

From discord #sidechain channel:

Upon further iteration of design and discussion with @hamdiallam, we settled on the following outline:
Have 3 kvstores, TxStore(Mapper?), DepositStore, BlockStore
In TxStore with prefixes in "":
"hash" + TxHash -> struct {plasma.Transaction, spent []bool, spenders [][32]byte, ConfirmationHash [32]byte}
"pos" + <pos> -> hash
"addr"+<addr> -> account
type Account struct {
    Balance *big.Int
    Unspent Position {just blk num + txindex} [requires to mapper calls, but saves a lot of space]
    Spent [same as above]    
}

DepositStore:
nonce -> struct{common.Address, *big.Int}

BlockStore:
same as current plasma store except with confirm sigs removed b/c they are accessible in TxStore

This allows for txhash -> all tx info (sigs/conf sigs/conf hashes), addr -> utxos, pos -> utxos/txs, utxo ->txhash
Ante handlers funcs can now be passed only the stores they need (deposit only needs depositStore)

This appears to be the most efficient solution storage wise, I believe there is no double storage, querying is made a lot easier and the mapping is a lot more intuitive. Thoughts?

Updates to design include:

Fixes #128

AdityaSripal commented 5 years ago

Could this include documentation of how application state is represented in the stores?

hamdiallam commented 5 years ago

All the getters in the store return a bool if the the key is not present in the db.

should we instead return an ErrDNE?

colin-axner commented 5 years ago

spend.go will need to be reworked a bit, feel free to restructure it, its pretty messy rn b/c of all the logic added to construct messages for the user.

codecov-io commented 5 years ago

Codecov Report

Merging #153 into develop will increase coverage by 9.88%. The diff coverage is 65.73%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #153      +/-   ##
===========================================
+ Coverage    49.02%   58.91%   +9.88%     
===========================================
  Files           26       27       +1     
  Lines         1077     1251     +174     
===========================================
+ Hits           528      737     +209     
+ Misses         452      396      -56     
- Partials        97      118      +21
Impacted Files Coverage Δ
plasma/deposit.go 56.25% <ø> (ø) :arrow_up:
plasma/block.go 84.61% <ø> (ø) :arrow_up:
msgs/spendMsg.go 0% <0%> (ø) :arrow_up:
store/errors.go 100% <100%> (ø)
eth/plasma.go 53.62% <100%> (ø) :arrow_up:
handlers/depositHandler.go 77.77% <100%> (-7.94%) :arrow_down:
plasma/position.go 61.32% <100%> (ø) :arrow_up:
plasma/input.go 66.66% <100%> (ø) :arrow_up:
store/keys.go 100% <100%> (ø)
msgs/depositMsg.go 35.71% <100%> (ø) :arrow_up:
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 531c7ab...b9ecdab. Read the comment docs.

AdityaSripal commented 5 years ago

Will look over spend.go tomorrow.

Starting to come together! Got a chance now to look more closely at all the stuff in this PR. Fantastic work as always @colin-axner!!