Commit graph

254 commits

Author SHA1 Message Date
Ignotus Peverell
be8d9633e4
rustfmt all the things 2018-03-04 00:19:54 +00:00
Antioch Peverell
cc12798d7a
Merkle Proofs (#716)
* family_branch() to recursively call family() up the branch
todo
  - we hit a peak, then we need to get to the root somehow
  - actually get the hashes to build the proof

* wip

* some additional testing around merkle tree branches

* track left/right branch for each sibling as we build the merkle path up

* MerkleProof and basic (incomplete) verify fn

* I think a MerkleProof verifies correctly now
need to test on test case with multiple peaks

* basic pmmr merkle proof working

* MerkleProof now serializable/deserializable

* coinbase maturity via merkle proof basically working

* ser/deser merkle proof into hex in api and wallet.dat

* cleanup

* wip - temporarily saving merkle proofs to the commit index

* assert merkle proof in store matches the rewound version
there are cases where it does not...

* commit

* commit

* can successfully rewind the output PMMR and generate a Merkle proof
need to fix the tests up now
and cleanup the code
and add docs for functions etc.

* core tests passing

* fixup chain tests using merkle proofs

* pool tests working with merkle proofs

* api tests working with merkle proof

* fix the broken comapct block hashing behavior
made nonce for short_ids explicit to help with this

* cleanup and comment as necessary

* cleanup variety of TODOs
2018-03-02 15:47:27 -05:00
Antioch Peverell
a20ffc700b
fix the broken comapct block hashing behavior (#738)
made nonce for short_ids explicit to help with this
2018-03-01 13:25:33 -05:00
Yeastplume
5d1f1af892
Bulletproof messages (#730)
* beginning to add bullet proof messages

* Updated core transaction creation to embed the output's value and switch commit hash as part of the rangeproof message

* formatting issue

* more formatting issues

* Removing conditional feature compliation.. just bulletproofs from now on

* ensure MAX_PROOF_SIZE uses bulletproof sizing instead of earlier version

* updated with switch commit committed to in extra data

* accidentally commented out bullet-proof-size feature
2018-02-27 21:11:55 +00:00
Antioch Peverell
5572fa075e
tx pool lookup for kernel short ids (compact block hydration) (#710)
* wip - basic tx pool lookup for kernel short ids (compact block hydration)

* use the nonce in the compact_block to correctly generate short_ids for lookup

* query the tx pool based on kernel short_ids

* tests passing

* cleanup some logging

* cleanup logging
2018-02-16 10:42:27 -05:00
Antioch Peverell
ebd801f14e
Transaction contain kernels. Transactions and blocks maintain a kernel offset (split key). (#681)
* WIP - split the key in final tx step
store "offset" on transaction itself

* rebase

* commit

* tx with offset

* got a test tx validating successfully using a sig from a split key and the appropriate offset

* sum up the offset for the block_header

* fix size tests for blocks and compact blocks (header now includes offset)

* use txs with offsets in most of the core tests
some tests now failing

* build kernel from k1G (k2 stored on tx, sum stored on header)

* commit

* tx now has vec of kernels
rework tx and kernel validation

* add test for tx cut_through

* wip - working on splitting in aggsig

* split the key when creating the initial sender aggsig context

* cleanup

* cleanup

* code needs claning up but split keys working for sender/receiver aggsig flow

* cleanup debug logging

* fix tests

* fix merge and basic cleanup

* fix keychain tests to use new tx_id
2018-02-13 10:35:30 -05:00
Ignotus Peverell
22c521eec8
[WIP] Abridged sync (#440)
* Util to zip and unzip directories
* First pass at sumtree request/response. Add message types, implement the exchange in the protocol, zip up the sumtree directory and stream the file over, with necessary adapter hooks.
* Implement the sumtree archive receive logicGets the sumtree archive data stream from the network and write it to a file. Unzip the file, place it at the right spot and reconstruct the sumtree data structure, rewinding where to the right spot.
* Sumtree hash structure validation
* Simplify sumtree backend buffering logic. The backend for a sumtree has to implement some in-memory buffering logic to provide a commit/rollback interface. The backend itself is an aggregate of 3 underlying storages (an append only file, a remove log and a skip list). The buffering was previously implemented both by the backend and some of the underlying storages. Now pushing back all buffering logic to the storages to keep the backend simpler.
* Add kernel append only store file to sumtrees. The chain sumtrees structure now also saves all kernels to a dedicated file. As that storage is implemented by the append only file wrapper, it's also rewind-aware.
* Full state validation. Checks that:
    - MMRs are sane (hash and sum each node)
    - Tree roots match the corresponding header
    - Kernel signatures are valid
    - Sum of all kernel excesses equals the sum of UTXO commitments
minus the supply
* Fast sync handoff to body sync. Once the fast-sync state is fully setup, get bacj in body sync
mode to get the full bodies of the last blocks we're missing.
* First fully working fast sync
* Facility in p2p conn to deal with attachments (raw binary after message).
* Re-introduced sumtree send and receive message handling using the above.
* Fixed test and finished updating all required db state after sumtree validation.
* Massaged a little bit the pipeline orphan check to still work after the new sumtrees have been setup.
* Various cleanup. Consolidated fast sync and full sync into a single function as they're very similar. Proper conditions to trigger a sumtree request and some checks on receiving it.
2018-02-09 22:32:16 +00:00
Quentin Le Sceller
fb46fad0ac Remove unused import and uniformize crates (#686)
* Removed unused crates
* Add listconnectedpeers in grin client
* Removed unused import and uniformize crates
2018-02-05 19:46:56 +00:00
Quentin Le Sceller
8a7eb94759 Update bitflags to ^0.1 (#682)
* Removed unused crates
* Add listconnectedpeers in grin client
* Update bitflags to ^0.1 globally
2018-02-05 19:43:54 +00:00
Simon B
86ff4e5bd0 Fix 658 and compiler complaints (#661)
* Tried but failed to fix `cargo build` complaint about unused #[macro use]. See also 7a803a8dc1
* Compiler complaints be-gone
* Give sumtree tests method-tagged folder names so they don't overwrite each others' files
Fixes #658
2018-01-28 06:12:33 +00:00
Yeastplume
783e4c250d
[WIP] Difficulty Adjustment Updates (#651)
* large updates for mining, fix async mode, will list changes in PR

* reset config and build defaults

* change to difficulty calculations

* tweaking mining params and tests

* tweaking to tests

* including pre-genesis data for difficulty adjustments, adding adjustment scenario tests

* further clarifying next_difficulty function

* moving tests out of consensus.rs

* pow test fix

* changing pre-genesis generation
2018-01-27 07:48:53 +00:00
AntiochP
4be259e0de
hashed switch commitments - BLAKE2(bJ, r) (#648)
* wip

* derive switch commit hash key from extended key in wallet

* fix failing pool test
2018-01-23 07:14:06 -05:00
AntiochP
cbd3b2ff87
hash (features|commitment) in output mmr (#615)
* experiment with lock_heights on outputs

* playing around with lock_height as part of the switch commitment hash

* cleanup

* include features in the switch commit hash key

* commit

* rebase off master

* commit

* cleanup

* missing docs

* rework coinbase maturity test to build valid tx

* pool and chain tests passing (inputs have switch commitments)

* commit

* cleanup

* check inputs spending coinbase outputs have valid lock_heights

* wip - got it building (tests still failing)

* use zero key for non coinbase switch commit hash

* fees and height wrong order...

* send output lock_height over to wallet via api

* no more header by height index
workaround this for wallet refresh and wallet restore

* refresh heights for unspent wallet outputs where missing

* TODO - might be slow?

* simplify - do not pass around lock_height for non coinbase outputs

* commit

* fix tests after merge

* build input vs coinbase_input
switch commit hash key encodes lock_height
cleanup output by commit index (currently broken...)

* is_unspent and get_unspent cleanup - we have no outputs, only switch_commit_hashes

* separate concept of utxo vs output in the api
utxos come from the sumtrees (and only the sumtrees, limited info)
outputs come from blocks (and we need to look them up via block height)

* cleanup

* better api support for block outputs with range proofs

* basic wallet operations appear to work
restore is not working fully
refresh refreshes heights correctly (at least appears to)

* wallet refresh and wallet restore appear to be working now

* fix core tests

* fix some mine_simple_chain tests

* fixup chain tests

* rework so pool tests pass

* wallet restore now safely habndles duplicate commitments (reused wallet keys)
for coinbase outputs where lock_height is _very_ important

* wip

* validate_coinbase_maturity
got things building
tests are failing

* lite vs full versions of is_unspent

* builds and working locally
zero-conf - what to do here?

* handle zero-conf edge case (use latest block)

* introduce OutputIdentifier, avoid leaking SumCommit everywhere

* fix the bad merge

* pool verifies coinbase maturity via is_matured
this uses sumtree in a consistent way

* cleanup

* add docs, cleanup build warnings

* fix core tests

* fix chain tests

* fix pool tests

* cleanup debug logging that we no longer need

* make out_block optional on an input (only care about it for spending coinbase outputs)

* cleanup

* bump the build
2018-01-16 22:03:40 -05:00
Simon B
8b2f9503c9 Make total_difficulty the sum of network difficulty [testnet2] (#523)
* Make total_difficulty the sum of network difficulty, not whatever the miner happened to mine.
  - Only for Testnet2 / Mainnet (hardforks Testnet1)
  - update chain::pipe validate_header to validate according to Testnet2 rules for cumulative difference

Fixes #280

* tests that should ignore (network) difficulty

* fn new_block is explained as "utility to create a block without worrying about the key or previous header" so it gets network difficulty := 0 too

* update tx pool tests (going with "minimum" for network difficulty for now)

* add ERR outputs about bannable offences
(#406 should know about these)

* whitespace fix

* mine_simple_chain: Probably DON'T overwrite difficulty (?)

* core/mod tests "reward_empty_block" and "reward_with_tx_block" tests set to use lowest network difficulty possible
2018-01-12 18:35:37 +00:00
Yeastplume
1199ed2cc1
[WIP] Aggsig Transactions (#530)
* First steps converting transaction workflow to be aggsig-enable

* integrating updated version of aggsig, which gives greater control over the contents of e

* added wallet transaction test to testing framework to enable testing the whole thing, completed interaction as far as inital response from recipient

* more aggsig work, final signature is produced now

* Construction of aggsig transaction now working to the point of the signature being built

* aggsig transactions working end-to-end in the nominal case

* refactor aggsig verify from commit and fix some tests

* more cleanup and test fixing

* cleaning up automated tests

* test+formatting fix
2018-01-10 19:36:27 +00:00
Simon B
17d5898677 Forgotten testnet1 cherries (#475)
* Very quick peer banning endpoint, helps with #406
* Ping heights (#407)
* add height to ping/ping
* reformat output
* fix p2p test
* Fix orphan handling, not related to current head. Fixes #412
* Check before borrow, fixes #267
* Not finding an output commit in pos is an AlreadySpent
* Fix race condition, sending before conn is ready
* Explicit error for unknown pos of a forked block
* Remove config outdated tests. Fix #333
* Check ref and try before borrow, fix #400
* We do not want to sync with old peers anyway
* Hide cargo compiler warning for unused NoopAdapter and unused test code. Add TODOs
2017-12-13 21:52:21 +00:00
Ignotus Peverell
91fdaa8320
Genesis block for known chains, mine dev chains (#269)
Renamed mining parameter mode to chain type, with existing types
of CI testing, user testing, testnet1 or mainnet. The public
chains (testnet1 and mainnet) come with their fully pre-defined
genesis block.

Still need to set the nonce and cycle for testnet1 genesis.
2017-11-15 16:49:15 -05:00
Ignotus Peverell
6ac2fe2a8c
Major fee bump to come to more reasonable values
Starting on the higher side for testnet to see how it goes in
practice. Introduced constants for each smaller unit.
2017-11-14 20:14:07 -05:00
AntiochP
c1656f7660
use the static secp instance everywhere (except the wallet) (#250) 2017-11-09 14:26:45 -05:00
Ignotus Peverell
e4ebb7c7cb
Cleanup HTTP APIs, update ports to avoid gap, rustfmt
Moved the HTTP APIs away from the REST endpoint abstraction and
to simpler Hyper handlers. Re-established all routes as v1.
Changed wallet receiver port to 13415 to avoid a gap in port
numbers.

Finally, rustfmt seems to have ignored specific files arguments,
running on everything.
2017-10-31 19:42:56 -04:00
Yeastplume
05d22cb632
changing secp import to tag, and consolidating Cargo.toml import (#220) 2017-10-31 23:20:55 +00:00
Ignotus Peverell
e2e24bc38e Transaction broadcast (#209)
* Add transaction broadcast to all known peers once they have been
accepted by our own transaction pool.
* Some debug log

Fixes #200
2017-10-25 21:06:24 +00:00
AntiochP
fa1f2f695b we now mine both txs so update test to reflect this (#189) 2017-10-18 23:23:37 +00:00
AntiochP
4d7b46b0b9 wallet can now optionally spend zero-confirmation txs (#188)
* wallet can now optionally spend zero-confirmation txs
* add rule to get_mineable_transactions based on total pool size
2017-10-18 20:47:37 +00:00
AntiochP
bab7bd7060 update_roots on pool to keep it consistent after reconciliation (#182)
* failing test case that exercises
prepare_mineable_transactions and reconcile_block
and highlights what appears to be unexpected behavior
* adjust the failing test - the failure state is where we have
a tx in the pool *but* it is not in the list of roots in the pool
* zero confirmation txs are now working
introduce update_roots to graph to ensure pool is consistent
after calling remove_pool_transaction
* move update_roots to sweep_transactions so we only call it once
rework update_roots to be more efficient
* use HashSet in reconcile_block to avoid marking txs multiple times
* use HashSet and not HashMap
return from mark_transaction early if already seen tx
2017-10-18 20:42:51 +00:00
Yeastplume
8f76746e84 Switch commitments (#179)
* Adding switch commit to grin outputs
* logging output fix
* adding switch commitment hash to sum tree node
* added hash_with to Hashed trait, to allow for hashing to include another writeable element
* adding hash_with as method in hashed trait
2017-10-16 21:23:10 +00:00
AntiochP
86420d4bca Shorter identifiers and call them key_id (not pubkey) (#175)
* rename pubkey -> key_id, these are key identifiers, not public keys
* reduce identifier seize to 10 bytes, get rid of fingerprints (identifiers are now small enough to use as-is)
* IDENTIFIER_SIZE const
* add FeeDispute error for when sender and recipient disagre on fee calculation (should never happen)
* does not need to be mut
* cleaned up some warnings
2017-10-13 04:45:07 +00:00
Yeastplume
8e382a7593 slog-rs logging (#171)
* added global slog instance, changed all logging macro formats to include logger instance
* adding configuration to logging, allowing for multiple log outputs
* updates to test, changes to build docs
* rustfmt
* moving logging functions into util crate
2017-10-12 16:56:44 +00:00
AntiochP
bf7c1fb44f add lock_height to Transaction and TxKernel (#167)
* add lock_height to Transaction and TxKernel, sign msg including both fee and lock_height in kernel
* make the order of the fields in tx and kernel more consistent
* rename to kernel_sig_msg
* add test to cover adding timelocked tx to pool, where tx is invalid based on current height of the blockchain
* add tests for adding timelocked txs to blocks (valid and otherwise)
2017-10-11 18:12:01 +00:00
AntiochP
dc0dbc62be Set approximate wallet fee to avoid LowFeeTransaction (#163)
Set approximate wallet fee when building a transaction so we avoid getting a LowFeeTransaction error from the pool

* rustfmt
2017-10-10 17:30:34 +00:00
Ignotus Peverell
0d26daadc5
Default values for pool config
Allows for deserializing config file without having to specify
all properties in it.
2017-10-08 17:45:31 +00:00
Ignotus Peverell
1e73e3aefc
Add a min fee to accept transactions in the pool
Configuration for a minum accept fee base for the transaction
pool. The base is multipled by a weight computed from the
transaction number of inputs, outputs and kernels. The transaction
fee is required to always be larger than the weight times the
base.

    min_fee = base * (-1*input_len + 4*output_len + kernel_len)

The weight is set to never be less than one.

Also added a configurable (and fairly naive for now) max pool
capacity in number of transactions.
2017-10-07 18:31:01 +00:00
AntiochP
3dd1dde00b Pass pubkey for coinbase (#159)
* store wallet output data in hashmap
* cleanup up commented out code
* pass pubkey/identifier and not derivation around to miner etc.
* fix failing tests
2017-10-07 17:38:41 +00:00
Yeastplume
da21388131 wee warning cleanup + build doc updates (#156)
* warning cleanup
* test compilation
* clarification on architecture in build doc, path export statement fix
2017-10-06 16:46:18 +00:00
Ignotus Peverell
ca7de0f42d
Painstakingly debugged pool test to avoid odd fees 2017-10-05 09:52:01 +00:00
AntiochP
e060b1953e rust-secp256k1-zkp breaking changes to support (#155)
Rewinding range proofs to recover transaction value from outputs
2017-10-05 21:40:46 +00:00
Yeastplume
e68a6a69bb Cuckoo miner fixes and configurable coinbase maturity (#154)
* cuckoo miner update+coinbase maturity
* set mining parameter mode on immature coinbase test
2017-10-04 17:44:22 +00:00
AntiochP
677d0a3a95 keychain crate (no more secretkeys in core) (#146)
* introduce grin_keychain, encapsulate derivation of secret_keys
* core compiles against keychain, tests don't run yet
* core tests are now passing against keychain
* wip - getting wallet working with keychain
* add util and keychain to travis test matrix
* basic test around key derivation
2017-10-03 00:02:31 +00:00
Ignotus Peverell
8504efb796
Cargo fmt all the things 2017-09-29 18:44:25 +00:00
Ignotus Peverell
36bcd3cc39 Integrate sum trees with the rest of the system (#116)
* Integrate PMMR and its persistent backend with the Chain
* Chain can set tree roots; PMMR backend discard
* Check spent and prune for each input in new block
* Handling of forks by rewinding the state
* More PMMR tests and fixes, mostly around rewind
* Rewrite get_unspent to use the sumtrees, fix remaining compilation issues
2017-09-27 23:46:32 +00:00
AntiochP
670aa11e5a expose "wallet info" on CLI (#132)
* expose "wallet info" on CLI
* add sleep and retry logic when obtaining wallet.lock
* fix pool test for immature coinbase
2017-09-24 04:40:31 +00:00
AntiochP
7c5b7d23e7 Replace secp256k1 directory with repository dependency (#126)
* workaround the "commitment is not a public key" problem by using to_two_keys() from rust-secp256k1-zkp
* remove secp256k1zkp, update the various Cargo.toml to use rust-secp256k1-zkp from external git repo, update code to not rely on to_pubkey (and use verify_from_commit)
* secp256k1zkp from git
* cleanup secp256k1 dependencies
* gitignore node1 and node2 dirs
2017-09-21 00:07:40 +00:00
AntiochP
44c8f9e22d fix the range_proof call (missing nonce param) (#125) 2017-09-13 20:00:48 +00:00
AntiochP
95a92eefc9 Cannot spend coinbase for N blocks (#111)
* use head_header in add_to_memory_pool
* add COINBASE_MATURITY const to consensus
* add coinbase maturity (wip) validaton rule to validate_block
* add coinbase maturity check to validate_block
* map errors in adapters - specific errors still wip
* reworked so adapter translates chain errors to pool errors (core errors not required)
* add test for spending immature coinbase in memory pool
* wip - add test to cover spending coinbase output in chain.process_block
* added test coverage around process_block - we have a problem with coinbase output commitments
* add a comment on the failing test
* process_block will now fail validation if we attempt to spend coinbase that has not yet matured
(remember to use a new reward_key for every block). test coverage in place to verify this
2017-09-12 17:24:24 +00:00
AntiochP
87cd0e5c58 added basic tests around range_proof (#121)
Pass nonce in to range_proof (we need it for rewind_range_proof, at least for testing)
2017-09-10 18:31:41 +00:00
Seamus Finnigan
9c649edfbf Use UTC in timestamps and fix broken header test (#105)
* Fix block header timestamp UTC and fix test
* Always use UTC for timestamp as time::Tm
2017-08-26 16:31:27 +00:00
AntiochP
3b4a48b2fd Cleanup build warnings (#87)
* minor cleanup - unused imports
* cleanup build warnings - unused vars
* make structs pub to get rid of the private_in_public lint warning
* missing docs on RangeProof
* add missing docs to store delete function
* cleaned up deprecation warning -
tokio_core -> tokio_io
complete() -> send()
2017-08-10 00:54:10 +00:00
Ignotus Peverell
40090fcdbc
Fix api & pool tests, add the crates to Travis 2017-07-18 17:33:49 +00:00
Ignotus Peverell
fbbd703e99
Protect wallet data file with a file lock
Operations on the wallet data file are now fenced by a lock to
avoid potentially messy concurrent modifications by multiple
processes (i.e. the wallet receiver and a send command). The lock
is done using a create-only lock file, which is an atomic
operation.
2017-06-14 21:42:58 -07:00
Ignotus Peverell
6523966f9e
Bug fixes in wallet and related API
Fixes a few loose ends in the full cycle of sending coins,
accepting them, pushing that transaction to the pool and having it
mined. More specifically:

* The API output endpoint needs to be a UTXO endpoint, as the
server can't make any guarantee about having a spent output.
* Bubbling up HTTP not found errors.
* Wallet output status checker now handles spent outputs.
* Transaction pool validates the transaction before accepting it.
* Fixed the operation API routes.
* Fixed too greedy wallet coin selection loop.
2017-06-12 16:41:27 -07:00
Ignotus Peverell
eb9cc7ef13
Integrate transaction pool with rest of the system
* Transactions coming from the network are now pushed to the pool
through the net adapter.
* New blocks accepted by the chain are sent to the pool for
eviction.
* The miner requests transactions from the pool to build its
blocks.
* The push API adds to the pool, removing the mock.
* Implementation of the adapter to the chain required by the pool
to get consistent UTXOs. Grossly unoptimized until we have the UTXO
MMR ready.
2017-06-10 12:51:33 -07:00
Ignotus Peverell
172c5e840b
TransactionPool uses non-dummy chain trait
Introduced new non-dummy trait for the blockchain as seen from the
pool that just produces a UTXO. Made to pool parametric on that
trait to get rid of the Box wrapper and still allow the test
implementation.
2017-06-10 11:31:05 -07:00
MoaningMyrtle
384554fc46 Change to pool->blockchain interface to avoid get_best_utxo_set (#60)
* Update DummyChain and DummyChainImpl to get_unspent
* Update pool to use get_unspent
2017-06-10 04:33:33 +02:00
MoaningMyrtle
23fd07be60 WIP: Tracking Transaction Pool Implementation (#48)
* Beginning work on pool design doc
* Refining data structures; adding connect capability
* Fleshing out the connectivity paths for the tx pool
* Bringing tx pool and orphan set add logic up into parent TransactionPool
* Use output's commitment as identifier in graph structures
* Breaking a bunch of stuff to start migration to output commitment as id instead of hash
* Wrapping up updates to pool using commitment keys, dummy blockchain. Contains lots of cleanup on the internal flow.
* Beginning work on new block reconciliation
* WIP: Replacing monolithic pool cleanup with mark-and-sweep, which greatly simplifies the logic.
* Laying the groundwork for pool tests; test tx generator
* WIP: More elaborate test helpers; starting work on more elaborate block acceptance test.
* Need DummyUtxoSet to actually apply blocks now
* Using search_for_best_output to validate output status in test_basic_pool_add
* Enable modification of chain while under shared pool ownership. Cleanup pending
* WIP: Begining to untangle the TransactionPool impl from Pool and Orphans data structures
* Finishing refactoring of pool block reconciliaition; getting tests working again
* Add metrics for graph sizes; prereq to pool size throttling
* Remove redundant search_for_available_output from pool graph container
* Minimum viable block builder: return all fully rooted txs
* Tests for block building procedure
* Delegate duplicate output checking to check_duplicate_outputs
* Delegate orphan reference resolution to resolve_orphan_refs
2017-05-19 17:22:08 +02:00