Commit graph

749 commits

Author SHA1 Message Date
Gary Yu
a0deb18e77
Update version of some crates (#1536)
Update version of some crates
2018-09-17 10:47:48 +08:00
Gary Yu
2c712fefff Small cleanup and perf improvement for peak_sizes_height and peaks (#1526)
* Small cleanup and perf improvement for  and

* rustfmt

* define a const 'ALL_ONES' for u64::MAX
2018-09-15 08:28:41 +01:00
yeastplume
e7eb26eed4 rustfmt 2018-09-14 15:25:07 +01:00
Gary Yu
3c1d8c3f8b Small cleanup and perf improvement for peak_map_height (#1521) 2018-09-13 09:59:49 -07:00
Antioch Peverell
dca0d52dcd
Cleanup transaction with offset (#1514)
* cleanup build::transaction_with_offset

* rustfmt
2018-09-12 12:17:36 +01:00
Antioch Peverell
07eefc4d6b
cache get_shift() and get_leaf_shift() in prune_list (#1495)
* cache shift and leaf_shift values in prune_list for fast lookup later

* rustfmt

* fixup core tests
2018-09-12 08:19:05 +01:00
Ignotus Peverell
a83404b22e
Simplify mining header serialization (#1509) 2018-09-11 20:31:05 -07:00
Antioch Peverell
77c2408c4e
Prevent duplicate output commitments (#1500)
* apply_output checks for duplicate commitment
not just a matching hash

* rustfmt
2018-09-11 19:36:00 +01:00
Ignotus Peverell
ecf20602d5
Hard fork tryout: better PoW encapsulation in block header (#1478)
* Improve encapsulation with ProofOfWork struct
* Add dual pow scaling factor, fix test
* Fix pre_pow serialization, chain tests
* Adjust header serialized size calc
* Hard fork handling, version-based serialization
2018-09-10 15:36:57 -07:00
Antioch Peverell
77765796ab
improve "check known" steps during process_block() (#1475)
* document what we do during pipe::apply_block()

* rustfmt

* wip

* rustfmt

* wip

* additional check_known_store and check_known_mmr checks in process_block

* rustfmt

* cleanup coinbase maturity check in process_block

* consolidate the "check in store" logic
add TODOs around the 50 block OldBlock logic

* rustfmt

* cleanup
2018-09-05 10:51:29 +01:00
John Tromp
c359c8aaf2 one day coinbase maturity (#1457)
* one day coinbase maturity

* make one day maturity a soft fork
2018-09-04 10:59:55 +01:00
hashmap
0172a3e020 Fix amount parsing (from string) (#1458)
* Fix amount parsing (from string). Fixes #1384
* Add conversion with string padding
* Use string padding
2018-09-03 15:55:04 -04:00
Quentin Le Sceller
544a296f77
Fix typos and unused imports (#1466)
* Fix typos and unused imports
2018-09-03 13:09:28 +02:00
Gary Yu
60d62bfb97 add a test case for transaction deserialize (#1356) (#1381)
* add a test case for transaction deserialize (#1356)
* update rust-secp256k1-zkp to grin_integration_23
* add transaction explicit validation
2018-09-01 15:14:10 -04:00
Gary Yu
d719493483 HeaderSync optimization (#1372) (#1400)
* improve: HeaderSync optimization (#1372)
* remove get_locator() optimization, which should be an independent pr for security review
* refactoring: move 'headers_streaming_body()' from Message to Protocol
* move 2 headers utils functions out of Protocol, and remove 'pub'
* support reading variable size of BlockHeader, from Cuckoo30 to Cuckoo36
* fix: use global::min_sizeshift() instead of hardcoded 30, because Cuckoo10 will be used for AutomatedTesting chain
* fix: should use global::proofsize() instead of hardcoded 42 when calculate serialized_size_of_header
* replace another 42 with global::proofsize()
2018-08-30 19:50:55 -04:00
Antioch Peverell
6d992e61d6 Add test coverage for verifier_cache 2018-08-30 15:08:16 -04:00
Antioch Peverell
939d391e0e
cache rangeproof and kernel signature verification results (#1419)
* wip - cache rangeproof verification

* rustfmt

* rustfmt

* rename to ok_verifier

* rustfmt

* wire in caching verifier in more places
skip rangeproof and kernel signature verification during deserialization

* rustfmt

* actually cache verification results via ok verifier

* rustfmt

* cleanup

* pass a cache around, not a verifier

* rustfmt

* cleanup trait shenanigans

* rustfmt

* core tests passing

* rustfmt

* rustfmt

* tests passing

* rustfmt

* verifier cache now takes vecs of data in and out

* rustfmt

* logging + rustfmt

* add docs and comments
2018-08-30 15:44:34 +01:00
Antioch Peverell
c334c557aa
Simplify tx.validate() and transaction::aggregate() (#1436)
* simplify tx validation and aggregation
we *only* need to account for reward when building a block from txs

* rustfmt

* cleanup and tests passing

* rustfmt

* better comments in with_reward()

* fix wallet tests
2018-08-28 20:00:25 +01:00
Antioch Peverell
bd03528d33
lightweight validation during deserialization (#1422)
* introduce validate_read (for lightweight validation when reading)

* rustfmt
2018-08-26 11:43:44 +01:00
Yeastplume
2251a82404
batch verify proofs during validation (#1412)
* batch verify proofs during validation

* don't attempt to batch verify proofs with empty vec
2018-08-23 18:53:42 +01:00
Antioch Peverell
7dfca6077c
Refactor compact block body (#1394)
* introduce CompactBlockBody

* rustfmt

* implement From<Block> for CompactBlock

* rustfmt

* remove debug logging

* wip

* rustfmt
2018-08-22 20:19:37 +01:00
Antioch Peverell
105bfacaa6
use chrono for timestamp in with_reward (#1406) 2018-08-22 15:40:24 +01:00
Ignotus Peverell
ef4f426474
Sort pool tx by fee over weight for mining (#1346)
* Sort pool tx by fee over weight for mining. Fixes #1105
* Bucketing dependent transactions before weighing. Minor tx weight fixes.
* Limit length of tx chain, cleanup and test fixes
* Cleanup all mining references to a hardcoded tx count
* Small test improvement, cleanup
2018-08-19 18:50:43 -04:00
Mike Dallas
adeaea4622 Truncate trailing zeroes in coin amounts (#1366)
* truncate coin amounts
* truncate datetimes
* fixed formatting
2018-08-17 13:05:35 -04:00
Gary Yu
54d3fc0af2 improve: use batch verification for txhashset rangeproof validation (#1321) (#1363)
* improve: use bullet rangeproof batch verification for txhashset validation (#1321)

* update rust-secp256k1-zkp to tag 'grin_integration_22'
2018-08-17 16:18:48 +01:00
Ignotus Peverell
6775112f61
Introduce cut_through method to avoid code duplication (#1355)
* Introduce cut_through method to avoid code duplication
* Improve error handling, fix sorting.
2018-08-15 16:20:33 -07:00
hashmap
99a66c1960
Consolidate validation in Block and Transaction (#1354)
* Consolidate validation in Block and Transaction

Introduce TransactionBody which is included into block and tx.
Fixes #1333
2018-08-15 23:14:48 +02:00
hashmap
37fa413329 Fix small issues found by fuzzing (#1360)
Overage and fee come from the network and may cause overflow if a message was corrupted or crafted to attack a server.
2018-08-15 11:55:25 -07:00
Quentin Le Sceller
6b74cf5098
Unpin croaring to version 0.3.2 (#1352) 2018-08-14 08:28:58 -04:00
Ignotus Peverell
6f590b3f88
Halve max block weight (#1347) 2018-08-13 14:06:53 -07:00
Ignotus Peverell
e9c987c075
Consolidate and cleanup tx aggregation (#1332)
* Include commitments non-duplicate checks in aggregate
* Remove said check from the pool
* Block building now uses tx aggregation to reduce duplication
2018-08-12 19:08:08 -07:00
Ignotus Peverell
4be97abbbb
Cleanup max sizes (#1345)
* Transaction max weight expressed in terms of block weight
* Cleaned up max block sizes, so everything is in therms of weight
* Cleanup block max constants
* Rename verify_size -> verify_weight
2018-08-12 13:02:30 -07:00
John Tromp
0d94d35a9d Simplify and optimize MMR routines (#1301)
* add new core mmr routine upon which others should be built more efficiently
* tons of pmmr optimizations and simplifications
* fix typo and extend docs
* change initial spaces to tab to fix indentation
2018-08-11 10:44:56 -07:00
antiochp
fb30b02f99
cleanup verify_weight code 2018-08-10 15:12:53 +01:00
antiochp
5ee11046a5
rework block validation to check input|output|kernel sizes consistently
with tx validation
2018-08-10 15:12:48 +01:00
antiochp
0ff1d86b22
rustfmt on core crate (not run for a while) 2018-08-10 15:00:18 +01:00
Antioch Peverell
ed88ad8bbc
cannot use unstable rustfmt features outside nightly toolchain (#1338)
* cannot use unstable rustfmt features outside nightly toolchain

* cleanup redundant rustfmt.toml files
2018-08-10 14:54:09 +01:00
Antioch Peverell
983a25248b
call tx.validate() as part of tx.read() (#1334)
and move some validation out of read() and into validate()
2018-08-10 13:57:47 +01:00
Antioch Peverell
9c05471979 Validate resulting tx after aggregation (and deaggregation) (#1331) 2018-08-09 16:37:31 -07:00
hashmap
ae3b1da18b Fix issues found by fuzz test (#1330)
Fuzz test found the folowing issues with reading block header:
* Unbounded cuckou_sizeshift field in Proof
* Different timestamp range after migration to chrono crate
2018-08-09 16:35:46 -07:00
hashmap
32662a0a16 Update fuzz in core crate
Fix compilation error in fuzz code after the wallet refactoring
2018-08-09 11:37:11 +02:00
Antioch Peverell
328d832bd6
cleanup verify_coinbase on block (#1326) 2018-08-08 09:47:30 +01:00
Quentin Le Sceller
3df050cc93 Check content before zip/unzip the txhashset (#1174)
* Check txhashset content before zip/unzip
* Add header in txhashset verification
* Add copy function and test
* Add file util
* Now check and remove unexpected files instead of just crashing
2018-08-02 19:16:16 -07:00
Gary Yu
b040aaa434 Fix: old time crate use 0..11 as the month, make mistake when switching to chrono Utc.ymd (#1304) (#1305) 2018-07-31 09:35:57 -07:00
Gary Yu
76f4915bf9 improve: time crate flagged as deprecated, switch to actively maintained chrono crate (#1297)
* improve: time crate flagged as deprecated, switch to actively maintained chrono crate

* improve: complete the switching from deprecated time crate to chrono crate, for all the tests part

* improve: complete switching to chrono crate, for the left tests in 'chain' and 'wallet'
2018-07-30 09:33:28 +01:00
Ivan Sorokin
5c029e3f87 Make grin.toml config optional (#1278)
* Make grin.toml config optional. Mirror exisiting config parameters in grin.toml to source code, so binary can run without a config file. Add test for it.
* fixup! Make grin.toml config optional
2018-07-29 17:48:24 -07:00
Antioch Peverell
a6dc48deae
add validation to tx to ensure we have no coinbase outputs or kernels in there (#1266)
* add validation to tx to ensure we have no coinbase outputs or kernels in there

* add some comments
2018-07-16 22:46:36 +01:00
yuntai
ad69dae9e5 Avoid potential 'attempt to add with overflow' panic (#1213) 2018-07-10 22:23:15 +01:00
Ignotus Peverell
34cf6ee3db
Genesis block and new seeds 2018-07-08 18:31:06 +01:00
Antioch Peverell
980378eb65
fix misbehaving simulnet fastsync test (#1227)
* fix misbehaving simulnet fastsync test
cleanup redundant cutoff vs bitmap params is rewind and check_compact

* make sure we do not verify full kernel history on a writeable txhashset extension
rework simulnet simulate_fast_sync test to be more robust

* fixup store tests

* sleep for a bit longer to give nodes time to update
their sync_state correctly

* tweak timing of simulate_block_propagation
2018-07-08 17:37:09 +01:00
Ignotus Peverell
567baa479f
Minor globals cleanup 2018-07-07 22:17:11 +01:00
Quentin Le Sceller
dd90aaedbc
Remove unused import and code (#1224)
* Remove unused import and code
2018-07-06 13:40:43 -04:00
Quentin Le Sceller
b5fe22dbd5 Bump to 0.3 (#1225) 2018-07-06 18:29:39 +01:00
Yeastplume
721a22b1c4
Simulnet test fix (#1222)
* remove lower time bound

* simulnet test issue

* re-introduce lower bound

* re-introduce lower bound
2018-07-06 11:42:54 +01:00
Yeastplume
f8cd5cf2a4
Initial block difficulty adjustment + difficulty adjustment scenario modification (#1217)
* Handle SIGINT and SIGTERM (#1180)

* Handle SIGINT and SIGTERM

* pin croaring to version 0.3.2 until we get the clang conflict sorted out (#1183)

* document proposals for - (#1190)

* conditional timelocked outputs, and
* conditional relative timelocked outputs

* problem with validation on rewind

* update difficulty scenarios to display much more data

* correct average sum output

* update pre-genesis block padding to just use previous block's data
2018-07-05 13:18:09 +01:00
Ignotus Peverell
6898b64628
Typo fix in T3 initial difficulty 2018-07-03 22:25:57 +01:00
Ignotus Peverell
1adffb5603
First config setup for T3, dummy genesis 2018-07-02 00:49:49 +01:00
Ignotus Peverell
1a410f115c
Cleanup a bunch of build warnings 2018-07-02 00:25:20 +01:00
Yeastplume
d2a84b7600
Error handling improvements (particularly in chain) (#1208)
* update error handling in chain and other modules to use error/errorkind

* sizeshift errorkind
2018-06-30 23:36:38 +01:00
Ignotus Peverell
f0d5406d0b
Fix cuckoo20 sizeshift in test 2018-06-30 05:07:24 +01:00
Ignotus Peverell
1398e0bf85
Accept multiple Cuckoo graph sizes (#1193)
* Added sizeshift to proof of work and encoding as VLQ
* Fix some loose ends to get things to compile
* Rename sizehift to min_sizeshift
  * Pipeline checks for PoW Cuckoo Cycle size shift and adjustment
factor before difficulty comparison.
  * Working delta+VLQ encoding of u64 PoW, unfortunately still a
little larger than u32, at least for Cuckoo30.
* Changed binary encoding of proof of work to a sequence of exact
compact bit representation of each nonce. Somewhat simpler,
shorter and matches the data to be hashed.
* Few fixes based on @tromp feedback:
* Max nonce is 2^(N-1)
* Need a separate constant for reference sizeshift
* Cuckoo implementation now conserves sizeshift. Test providing a
block at higher sizeshift.
* Last small overflow protection
2018-06-29 18:41:28 +01:00
Antioch Peverell
1df409fa69
verify coinbase maturity via output_mmr_size (#1203)
* we do not need Merkle proofs to spend coinbase outputs
we only need the output_mmr_size from the block header

* tests working with no Merkle proofs in inputs
2018-06-28 21:56:07 -04:00
Antioch Peverell
d0f8d325f2
implement prune_list as a bitmap (#1179) (#1206)
* implement prune_list as a bitmap
and simplify

* cleanup prune_list, use maximum()

* handle migration of prune_list to new bitmap prun file

* legacy filename consts

* cleanup and docs
2018-06-28 20:53:00 -04:00
Antioch Peverell
14667bfad6
cleanup path fn and add test coverage (#1201) 2018-06-26 09:42:12 -04:00
Yeastplume
38a7936521
Use updated bulletproof API (#1194) 2018-06-25 12:28:56 +01:00
Ignotus Peverell
3530b8300c
Remove redundant hashing of header before proof of work (#1118)
We used to hash the hash of the header, needlessly. This also
makes a few function signatures more explicit.

Note that this is consensus breaking and should be accompanied
with a similar change on the cuckoo-pow repository:

6fcecf516a

Fixes #1066
2018-06-22 22:59:56 +01:00
Ignotus Peverell
24cd5bc3e3
Less truncation in difficulty calculation (#1116) 2018-06-22 22:30:02 +01:00
yeastplume
e7c380836b rustfmt 2018-06-22 09:44:38 +01:00
Ignotus Peverell
d189770080 Wallet LMDB backend (#1151)
* Migrate main node store to LMDB

In preparation to using LMDB as a wallet database, migrate the
node db. There's no point in having 2 key-value stores.
In addition LMDB provides a few advantages as a node db, namely a
much faster build (compared to RocksDb), lesser dependencies and
transactions.

* Migrated p2p store to lmdb, stuff compiles

* More fixes, chain tests starting to pass

* Fixed txhashset rollback messing with block save and general batch delimitation. Chain tests passing.

* rustfmt

* LMDB max map size of 10MB isn't really workable. Half TB seems reasonable.

* Fix wallet tests

* Rather crucial commit was missing

* rustfmt

* Fixing new merged tests following lmdb changes

* rustfmt

* * Make txhashset validation read-only on fast sync to avoid having
a really long open transaction.
* Fix deadlock in new block processing, batch should always be
created within a txhashset lock (when they interact).

* Comment about batch and txhashset interlacing

* Fix store tests to use batch

* Externalize wallet config and seed

* Converted direct read access to file outputs map to an iterator

* Cleaned up and simplified wallet Backend trait:

* No more direct mutable access to internal structures (HashMap)
* Batch interface for all writes
* Remove unneeded read wrapper (read_wallet)

* rustfmt

* First (incomplete) pass at wallet LMDB backend

* Progressing on lmdb backent iml

* Added batch impl for LMDB wallet backend. Pretty much done with it, but not sure how to deal with commit (owned).

* rustfmt

* Wrapping LMDB batch around a refcell to work around borrow rules

* Compilation up to grin chain
2018-06-22 09:08:06 +01:00
Ignotus Peverell
0967a5302b
Kernel sum and MMR sizes in block header (#1163)
* Add kernel commitments sum and kernel and output MMR sizes to block header
* Sum a block without including previous sums, cleanup. Blocks are now summed and validated based on their own totals and not the totals since genesis. This allows to get rid of BlockSum and simplified the setting of a new block's roots, kernel sum and MMR sizes. Fixes #116
* Additional kernel MMR validation to check all prior header roots successively
* Wallet tests fix
2018-06-21 02:30:22 +01:00
Antioch Peverell
0ff6763ee6
[consensus breaking] New Improved Merkle Proofs (#1119)
* new improved Merkle proofs

* fix pool and chain tests

* fixup core tests after the merge
2018-06-20 15:18:52 -04:00
Antioch Peverell
028b14d9d9
Replace rm_log with leaf_set (compact bitmap) (#1147)
* only store leaves in rm_log

* cleanup

* commit

* add failing test to cover case where we compact
an already compacted data file

* fix the logic for pruning the data file

* rm_log only contains leaves
prunelist only contains non-leaf subtree roots

* cleanup

* commit

* bitmap impl running in parallel

* rustfmt

* this is better - rewind unremoves outpu pos spent by rewound inputs

* commit

* commit

* pass bitmap around when rewinding

* store and retrieve input bitmap per block from the db

* Replace the RemoveLog with the UTXO set.

* utxo set starting to pass tests

* stuff works...

* split store types out
added some tests to compare the performance of the rm_log and the proposed utxo_set

* pull prune_list out into standalone file

* cleanup, get rid of unused height param

* cleanup and add doc comments

* add support for migrating rm_log to utxo_set

* take snapshot of utxo file during fast sync
implement migration of rm_log -> utxo_set

* rename rewound_copy to snapshot

* fixup pmmr tests to reflect cutoff_pos

* cleanup unused import

* check_compact needs to rewind the utxo_set as appropriate

* fix pool tests

* fixup core tests

* cache block_input_bitmaps via LruCache in store

* cache block header on initial write to db

* rename utxo_set -> leaf_set
and remove references to "spent" in grin_store

* better document the rewind behavior
2018-06-18 11:18:38 -04:00
Quentin Le Sceller
a30ee88236
Cleanup imports (#1161)
Reorganize imports
2018-06-14 08:16:14 -04:00
Yeastplume
88616fd341
[WIP] Updates to support web-wallet (#1160)
* updates to support web wallet workflow

* rustfmt

* functions to support wallet, error handling

* rustfmt

* rebase rustfmt

* test fix
2018-06-13 21:58:45 +01:00
Quentin Le Sceller
8f4dbfa540 Many typo fixes (#1158)
* Typo fix
* Parameterise
2018-06-13 17:03:34 +01:00
Quentin Le Sceller
169ffee607 Externalize PMMR test (#1154)
Externalize PMMR tests into their own file under `tests/`
2018-06-11 22:01:30 +01:00
Antioch Peverell
edc01bb05a Add verify_cut_through to both transaction and block (#1130)
We have no code that will produce a non-cut-through version of either
so this should be safe to add in testnet2
2018-06-10 20:59:58 +01:00
Ignotus Peverell
af178f82f8
Refactor the Keychain to be based on a trait (#1146)
* First pass at restructuring the keychain crate and introducing a Keychain trait
* Parameterized everything that had to. Stuff compiles.
* More stuff compiles, fix most tests
* Big merge, pushing down opening the keychain forced adding factory methods on trait
* Test fixes for pool and servers crate
2018-06-08 06:21:54 +01:00
Quentin Le Sceller
1255ea2224
Upgrade and uniformize dependencies (#1138)
* Remove unused DandelionConfig

* Cargo upgrade and cleanup
2018-06-05 13:26:32 -04:00
Ignotus Peverell
057eb2dcb8
Minor typo fix 2018-06-05 06:46:07 +01:00
Quentin Le Sceller
663733e72b
Replace try! for ? (#1134)
* Replace try for ?
2018-06-04 12:05:49 -04:00
Antioch Peverell
0ecadd3486
move verify_kernel_sums into committed trait (#1131) 2018-06-02 19:00:44 +01:00
Antioch Peverell
6fd2afccb4
block::new() now sets a random pow on the header (#1128) 2018-06-02 15:17:07 +01:00
hashmap
2fa32d15ce Rustify core/src/core (#1122)
Small refactoring of one folder, if it makes sense I could extend the scope.
* Remove some cloning (real and just verbosity in the code)
* Naming conventions like to/into*
* Some Clippy's suggestions

I found that we don't use field init shorthand syntax, so I didn't touch this part, was it discussed before?
2018-06-01 20:41:26 +01:00
Yeastplume
7812a02233
Libwallet refactoring - Library functions + ErrorTypes (#1113)
* move checker and rename to updater

* rustfmt

* complete checker/updater move

* rustfmt

* move libwallet error into separate file

* rustfmt

* starting to sort our error types

* updating errors in libtx and libwallet

* rustfmt

* factor out error type

* rustfmt

* compiling, errors split into libwallet and wallet errors

* rustfmt

* changing user error reporting to new format

* rustfmt

* clean up error types

* clean up error types

* move restore into libwallet

* rustfmt
2018-06-01 15:06:59 +01:00
Antioch Peverell
4fda7a6899
Minimal Transaction Pool (#1067)
* verify a tx like we verify a block (experimental)

* first minimal_pool test up and running but not testing what we need to

* rework tx_pool validation to use txhashset extension

* minimal tx pool wired up but rough

* works locally (rough statew though)
delete "legacy" pool and graph code

* rework the new pool into TransactionPool and Pool impls

* rework pool to store pool entries
with associated timer and source etc.

* all_transactions

* extra_txs so we can validate stempool against existing txpool

* rework reconcile_block

* txhashset apply_raw_tx can now rewind to a checkpoint (prev raw tx)

* wip - txhashset tx tests

* more flexible rewind on MMRs

* add tests to cover apply_raw_txs on txhashset extension

* add_to_stempool and add_to_txpool

* deaggregate multi kernel tx when adding to txpoool

* handle freshness in stempool
handle propagation of stempool txs via dandelion monitor

* patience timer and fluff if we cannot propagate
to next relay

* aggregate and fluff stempool is we have no relay

* refactor coinbase maturity

* rewrote basic tx pool tests to use a real txhashset via chain adapter

* rework dandelion monitor to reflect recent discussion
works locally but needs a cleanup

* refactor dandelion_monitor - split out phases

* more pool test coverage

* remove old test code from pool (still wip)

* block_building and block_reconciliation tests

* tracked down chain test failure...

* fix test_coinbase_maturity

* dandelion_monitor now runs...

* refactor dandelion config, shared across p2p and pool components

* fix pool tests with new config

* fix p2p tests

* rework tx pool to deal with duplicate commitments (testnet2 limitation)

* cleanup and address some PR feedback

* add big comment about pre_tx...
2018-05-30 16:57:13 -04:00
Yeastplume
82ed280625
[WIP] Factoring out wallet traits and continued wallet library work (#1096)
* rename wallet libs

* rename transaction.rs to slate.rs

* rename transaction.rs to slate.rs

* move some types into libwallet/types

* rustfmt

* rename libtransaction libtx

* rename libtransaction libtx

* change types.rs to file_wallet

* rustfmt

* rename WalletData to FileWallet

* refactoring WalletBackend types out

* rustfmt

* All compiling, at least

* rustfmt

* fix FileWallet paths to persist

* rustfmt

* re-ignore wallet integration test
2018-05-30 17:48:32 +01:00
Quentin Le Sceller
ec3c2e89a4 Store and communicate ban reason (#1085)
* Add read_i32 and write_i32
* Store and send reason for ban
* Client corruption ban reason
* Forgotten max message size
2018-05-29 03:45:31 +01:00
Yeastplume
85285473bd
[WIP] Wallet refactor - part 3 (#1072)
* Beginning to rework aggsig library workflow

* more refactoring of transaction api

* whoever does round 1 first creates offset

* slate finalisation now context-free, so anyone can do it

* remove concept of transaction phase

* remove slate phase enum

* update actual send/receive code with new transaction lib workflow
2018-05-21 16:28:11 +01:00
Yeastplume
4bbaa8d05f
Move aggsig transaction building functions into separate lib (#1061)
* refactoring transaction building code

* serialise return transaction

* move shared functions into transactions, ensure wallet manipulation is only done outside of aggsig transaction lib

* remove unneeded wallet config from fn

* adding test functions to facilitate libwallet transaction testing

* rustfmt

* refactoring checker somewhat, adding ability to create and transactions against local copy of chain for simpler testing

* finish transaction testing functionality which verifies transactions work properly

* Remove wallet output manipulation from transaction building lib

* ensure sender expects full transaction back on last phase

* ensure sender expects full transaction back on last phase
2018-05-16 13:18:09 +01:00
Antioch Peverell
0d9242e5dc
refactor on master, pass in offset as blinding_factor (#1064) 2018-05-13 13:59:27 -04:00
Yeastplume
4121ea1240
Wallet+Keychain refactoring (#1035)
* beginning to refactor keychain into wallet lib

* rustfmt

* more refactor of aggsig lib, simplify aggsig context manager, hold instance statically for now

* clean some warnings

* clean some warnings

* fix wallet send test a bit

* fix core tests, move wallet dependent tests into integration tests

* repair chain tests

* refactor/fix pool tests

* fix wallet tests, moved from keychain

* add wallet tests
2018-05-09 10:15:58 +01:00
Antioch Peverell
f90506d869
txhashset extension now implements Committed (#1049)
* txhashset now implements committed for consistency

* rustfmt and cleanup
2018-05-08 10:23:33 -04:00
Antioch Peverell
4dd94ff39e
[testnet2] Store output sum (#1043)
* block sums and reworked block validation
read and write block_sums
refactor validate on both block and txhashset
write block_sum on fast sync
we store the kernel_sum (need to account for the offset)

* block_sums

* rustfmt

* cleanup
2018-05-07 09:21:41 -04:00
Antioch Peverell
e22d025dc8 Simplify block marker metadata (#985)
* wip BlockMarker struct, get rid of PMMRMetadata
* use rewind to init the txhashet correctly on startup, we do not need to track pos via metadata (we have block markers), we do not need to open the txhashset with specific pos (we have rewind)
* better logging on init
* keep rewinding and validating on init, to find a good block
* use validate_roots on chain init
2018-04-24 19:53:01 +00:00
Quentin Le Sceller
55f6e3e63f
Anti-aggregation mechanism for multi-kernel transaction (#984)
* Test multi kernel deaggregation

* Add aggregate without cut_through and deaggregate function

* Add deaggregate function in pool and test

* Rustfmt

* Add deaggregate_and_add_to_memory_pool

* Deaggregate regular multi kernel transaction by default

* Rustfmt

* Add error type faileddeaggregation

* Add find candidates function

* Rustfmt

* Use intersection of sets instead of for comparisons

* Rustfmt

* Removed unnecessary if

* Stricter verification with is_subset

* Rustfmt
2018-04-24 15:47:13 -04:00
Yeastplume
4c6a193e01
[WIP] Miner removal (#979)
* Beginning to remove in-process miner

* rustfmt

* rustfmt

* rustfmt

* rustfmt

* remove pow crate and put remnants into core

* rustfmt

* fix test compilation in core and chain

* rustfmt

* Updating server tests to use test miner

* rustfmt

* rustfmt

* remove pow from test matrix

* adding basic stratum stats to TUI

* run stratum server at all times, and halt messages while syncing

* fix core tests

* add ability to run internal test miner for cuckoo 16 testing

* modify build instructions
2018-04-24 09:18:24 +01:00
Antioch Peverell
ef304ee9c1
add block header cache to store (#996)
* WIP - add blocks header cache to store
The DifficultyIter is expensive to use when validating block headers.

* lru_cache

* rustfmt

* cleanup
2018-04-23 14:55:25 -04:00
Antioch Peverell
ced6e647b8
still do not fully understand what PhantomData is *for* exactly (#991)
but standardized naming and usage to match https://doc.rust-lang.org/beta/nomicon/phantom-data.html
so at least it looks similar to the official docs
2018-04-21 17:03:45 -04:00
Antioch Peverell
f0cf903adc
fix various issues with rewinding data file (#983)
* fix issue with rewinding data file
also fix fragility around an empty MMR (and the memory map)

* cleanup
2018-04-19 19:52:46 +01:00
Ziyuan Liu
a8cc58bb89 Remove oddfee error references + validation check (#975) 2018-04-18 12:21:21 +01:00
Quentin Le Sceller
bd64c6099f Add aggregate function for multi-kernel transaction (#966)
* Add aggregate function

* Rustfmt

* Add multikernel tx test

* Rustfmt

* Add test bad multi-kernel transaction

* Add sorting

* Modified multikernel test
2018-04-17 21:40:51 +01:00
hashmap
7bad33d249 Merkle proofs fee (#898)
* Refactoring before new functionality

* Simplify and use just count of proofs
2018-04-17 18:09:29 +01:00
Yeastplume
dcdf654bc9
[WIP] Core PMMR and API updates to support wallet restore (#950)
* update pmmr to get batch of elements by insertion position

* update pmmr to get batch of elements by insertion position

* add api + chain calls to get traversed outputs back out

* add api + chain calls to get traversed outputs back out

* first pass getting wallet restore to work again with updated utxo-walking api
2018-04-11 10:02:07 +01:00
Antioch Peverell
6ceed79c03 Use hashable_ord on short_ids (#932) 2018-04-05 15:48:30 +00:00
Riccardo Casatta
40212942da use std lib function in pmmr for all_ones() and most_significant_pos() (#924)
* use std lib function in pmmr for all_ones() and most_significant_pos()

* fix all_ones() edge case with 0 and add comparison tests with old functions
2018-04-04 13:25:03 +01:00
John Tromp
c3939107a5 Avoid repeated truncation in difficulty adjust + minor refactoring (#915)
* avoid repeated truncation in difficulty adjust + minor refactoring
* reinstate needed low-diffculty exception on dampening
* leave consensus breaking change for later one line change; obsolete lower testnet1 max target
2018-03-30 18:21:06 +00:00
Simon B
3e3fe6cae6 Testnet2 small fixes (#899)
* add hint for gcc-5 for building CUDA plugin
* add N_BLOCks comment for >=6GB GPU cards
* minor logging cleanup
* mark to be kept + reformat as "@ height [hash]"
* show CuckooNN + better wording
2018-03-29 15:56:46 +00:00
Yeastplume
19bedff664
Difficulty scenario fix (#892)
* fix difficulty scenario to match testnet2

* fix difficulty scenario to match testnet2
2018-03-27 22:11:52 +01:00
Yeastplume
6a6e600e48
tests for difficulty adjustment scenarios (#887)
* tests for difficulty adjustment scenarios

* ignore test
2018-03-27 19:15:42 +01:00
Ignotus Peverell
16beeca8c9
Correct chain initialization at genesis 2018-03-26 17:38:27 +01:00
Ignotus Peverell
74674c2307
Hopefully last genesis update... 2018-03-26 17:36:54 +01:00
Ignotus Peverell
aa0e488e07
Genesis update with correct nonce... 2018-03-26 17:32:10 +01:00
Ignotus Peverell
e0594d81fc
Genesis update with correct month 2018-03-26 17:31:13 +01:00
Ignotus Peverell
f3fc26c5c9
Genesis update with 172 difficulty 2018-03-26 16:12:18 +01:00
Ignotus Peverell
327293d28e Genesis, version changes and doc for testnet2 (#865)
* Bump up crates versions

* Finally add a Cargo.lock to avoid dependency breakages

* Build doc update for testnet2

* Fix test framework not really using its mining config

* Testnet2 genesis, best so far at 128 difficulty (a nice number)

* Minor build doc update
2018-03-26 10:48:46 +01:00
John Tromp
a327427178 0-based positions, bag peaks right-to-left with mmr size as index (#863)
* 0-based positions, bag peaks right-to-left with mmr size as index
* fix remaining instances of hash_with_index
* fix pmmr test
2018-03-26 02:26:11 +00:00
Simon B
9285de2c24 Here is a case where ~ is needed, to allow cargo update to only touch the patch level version (third number). Anything else than ~ means that both first numbers can be raised, so "2.1" updaates to "2.2" (#866) 2018-03-25 20:08:38 +00:00
Ignotus Peverell
2bf656646c
Force slog version to 2.1 (2.2 broke some traits) 2018-03-25 19:54:41 +01:00
Simon B
f9b87164e7 Idiomatic cargo toml (#862)
* Specify versions SemVer-style
 - slog and serde
* Comments for not update-able pre-1.0 crates:
 - urlencoded at "0.5" since 0.6+ lacks trait `plugin::Plugin<iron::Request<'_, '_>>`
* alpha-sort deps
* Specify versions SemVer-style
 - backtrace, bitflags, blake2-rfc, bodyparser, built, byteorder
 - chrono, clap, demonize, enum_primitive, env_logger
 - failure, failure_derive, futures
 - hyper, iron, itertools, lazy_static, libc
 - memmap, mount, net2, num_bigint, prettytable-rs
 - rand, regex, rocksdb, router, siphasher
 - term, time, tokio-core, tokio-retry, urlencoded, uuid, walkdir, zip
2018-03-25 17:44:27 +00:00
Alexey Miroshkin
bb134758e7 Rename Hash::zero() to Hash::default() (#858)
It is more idiomatic, also `zero` is misleading in context of `+` operator.
2018-03-23 23:35:10 +00:00
Antioch Peverell
388beafb65 Standardize and cleanup SerializationMode (#856) 2018-03-23 23:34:50 +00:00
Antioch Peverell
7a8d6147f4 Split pmmr.get() into get_hash() and get_data() (#855) 2018-03-23 23:33:59 +00:00
Yeastplume
80887196a8
Restore wallet restore (#843)
* adding appropriate message to bulletproofs to allow for restore

* rustfmt

* should work, now test

* rustfmt

* fix to wallet restore, works now

* fix pool tests

* fix pool tests

* rustfmt
2018-03-23 10:13:57 +00:00
Alexey Miroshkin
eb226beea8 Introduce fuzz tests for core (#844)
This PR introduces fuzz tests and address #592
2018-03-22 16:53:47 +00:00
Ignotus Peverell
9d366fe492
Fix difficulty calc for short chains 2018-03-22 16:38:42 +00:00
Ignotus Peverell
054114027f
Index first when hashing nodes in MMR. Fixes #814 2018-03-22 04:58:25 +00:00
Ignotus Peverell
1300d7a745
Dummy change to testnet2 genesis 2018-03-22 04:55:34 +00:00
Ignotus Peverell
ca8447f3bd
Removed all switch commitment usages, including restore (#841)
* Removed all switch commitment usages, including restore
* Fixed pool tests
* Fix keychain tests
* Get rid of the switch key in keychain
2018-03-22 00:10:11 +00:00
Antioch Peverell
5a47a17101
remove redundant verify_proof call (#835)
* we verify rangeproofs in sum_commitments (in verify_kernels)
remove this redundant (and expensive) rangeproof verification

* rustfmt
2018-03-21 14:55:41 -04:00
Simon B
4fa9ccc4f7 Cargo.toml (#818)
* Make sure no grin crates get published by mistake: https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish--field-optional
* add missing workspace = '..', [workspace docs for interested readers](https://doc.rust-lang.org/cargo/reference/manifest.html#the-workspace-section)
* dev- or dev_ works equally well, but dev- is what's typically used
* authors = Grin Developers <maillist>
* [dependencies] keep grin-* at the end + readability
2018-03-20 18:21:29 +00:00
Yeastplume
4886fa08b2
TUI Difficulty stats for past few blocks (#805)
* added mining subview, changed main menu selection

* collecting difficulty stats from miner

* add diff calc view, separate server stats

* rustfmt

* block difficulty data output

* rustfmt

* ensure diff data is always shown

* don't write to stderr when tui running
2018-03-19 19:23:58 +00:00
Roman Zeyde
d4eb24d16a Fix a small comment typo (#810) 2018-03-19 16:55:17 +00:00
Ignotus Peverell
2fb97eb87f
Minor increase to max tx input count 2018-03-16 22:26:36 +00:00
Alexey Miroshkin
1b3541245a Fix limits for Transaction (#800)
In prevPRr I set them too high, also typos in comments were fixed.
2018-03-16 22:23:10 +00:00
Alexey Miroshkin
c96838d54d Improve bounding block timestamp (#793)
Fixes #783.
* 2^60 still fails on OSX, experimentally found safe max 2^55
* Handle negative values

I tried to use .abs(), unfortuantely fuzz test kills it with
`panicked at 'attempt to negate with overflow', /Users/travis/build/rust-lang/rust/src/libcore/num/mod.rs:1146:17`
2018-03-16 22:20:40 +00:00
Yeastplume
b53b84b0c6 Move nonce/pow to end of block header, change post-pow hash (#794)
* move nonce/pow to end of block header, update call to cuckoo-miner
* change header hash to be pow only
* fix genesis block miner and tests
2018-03-16 19:04:31 +00:00
Alexey Miroshkin
1bad7188b7 Fix Readable impl for Transaction (#795)
Fuzz test demonstrated that the current implemenation panics on reading from the network when serialized tx. Contains for example huge number of input or outputs. It allows a mailicious sender
to kill the server.
2018-03-16 19:02:22 +00:00
Antioch Peverell
cb71386097
hash with the pos for non-leaf nodes (#788)
* hash_with_index on non-leaf nodes
rework the Merkle proof to include the pos of each sibling in the path

* rustfmt

* cleanup

* cleanup

* use get_from_file in validate (children may have been "removed")

* rustfmt

* fixup store tests
2018-03-16 10:45:58 -04:00
Antioch Peverell
2552b34118
remove difficulty field from block_header (derive from total_difficulty) (#777)
* remove difficulty field from block_header (derive from total_difficulty)

* address feedback on PR and general cleanup

* rustfmt

* rework pow/difficulty validation in pipe::validate_header
now that we only have total_difficulty available

* cleanup various todos

* rustfmt

* rework DifficultyIterator to track header and prev_header state

* rustfmt caught some garbage syntax

* cleanup
2018-03-15 15:16:34 -04:00
Ignotus Peverell
e4871065b0
Bounding block timestamp to avoid surprises. Fixes #783 2018-03-15 18:37:17 +00:00
Yeastplume
244fc8d32e
PMMR data compaction (#784)
* fix and re-introduce data file compaction

* rustfmt

* remove commented line

* test cleanup

* remove println

* fix to core test
2018-03-15 17:12:30 +00:00
Antioch Peverell
00bfc4ec38
add dump_stats so we can see pmmr sizes after compaction (#785)
* add dump_stats so we can see pmmr sizes after compaction

* rustfmt

* fix tests with dump_stats()
2018-03-15 12:53:40 -04:00
Antioch Peverell
6a1a45e21f
store "total kernel offset" on block header (#769)
* move from storing per block kernel_offset in the block header
to storing the total accumulated kernel offset on each block header

* rustfmt

* cleanup
2018-03-14 11:22:09 -04:00
Antioch Peverell
65633c7611
check_compact retains leaves and roots until parents are pruned (#753)
* wip

* failing test for being too eager when pruning a sibling

* commit

* rustfmt

* [WIP] modified get_shift and get_leaf_shift to account for leaving "pruned but not compacted" leaves in place
Note: this currently breaks check_compact as nothing else is aware of the modified behavior

* rustfmt

* commit

* rustfmt

* basic prune/compact/shift working

* rustfmt

* commit

* rustfmt

* next_pruned_idx working (I think)

* commit

* horizon test uncovered some subtle issues - wip

* rustfmt

* cleanup

* rustfmt

* commit

* cleanup

* cleanup

* commit

* rustfmt

* contains -> binary_search

* rustfmt

* no need for height==0 special case

* wip - works for single compact, 2nd one breaks the mmr hashes

* commit

* rustfmt

* fixed it (needs a lot of cleanup)
we were not traversing all the way up to the peak if we pruned an entire tree
so rm_log and prune list were inconsistent

* multiple compact steps are working
data file not being copmacted currently (still to investigate)

* cleanup store tests

* cleanup

* cleanup up debug

* rustfmt

* take kernel offsets into account when summing kernels and outputs for full txhashset validation
validate chain state pre and post compaction

* rustfmt

* fix wallet refresh (we need block height to be refreshed on non-coinbase outputs)
otherwise we cannot spend them...

* rustfmt
2018-03-13 14:22:34 -04:00
Ignotus Peverell
65c0a4b7b0
Fee burning no more. Fixes #767 2018-03-13 02:39:22 +00:00
Ignotus Peverell
a9d1b76414
Compaction of pruned data for chain data structures (#746)
* Implementation of compaction for the chain. Single entry point on the chain triggers compaction of all MMRs as well as the cleanup of the positional index and full blocks.
* API endpoint, additional tests and more fixes for compaction
* Also prune PMMR metadata, minor bug fix
* PMMR store tests fix
2018-03-06 17:58:33 +00:00
Antioch Peverell
449fabf24f
cannot use write_mode in rustfmt.toml in stable (get rid of the warnings) (#752) 2018-03-05 15:23:52 -05:00
Yeastplume
1143d84238
Remove Sumtree References and disambiguate some naming (#747)
* start of renamathon

* api renaming

* Rename UTXO-Output to lessen ambiguity

* compile warning

* compile error

* readme fix

* remove file commit in error
2018-03-05 19:33:44 +00:00
Yeastplume
90f844d382
Include index as part of pmmr element hash (#748)
* storing index as part of pmmr element hash

* factor out hash_with_index into generic trait impl

* tighten up trait bounds for PMMRable
2018-03-05 15:05:42 +00:00
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
Alexey Miroshkin
9e11afe8a2 Error handling with failure (using Error and ErrorKind) (#713)
* Initial version

* store failure parameters inside ErrorKind variants

* continue failure transformation

* 4 errors left

* still two errors

* return old code back

* finally compiling

* Fix compilation and test errors after merge
2018-02-28 12:56:09 -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
Ignotus Peverell
341a3c9f4d
Minor cleanup, range proof pmmr validation and tests 2018-02-24 23:40:13 +00:00
Ignotus Peverell
3ab616b8be
Fix range proof deser (length issue) 2018-02-24 23:40:12 +00:00
Yeastplume
05d1c6c817
Take the 'Sum' out of 'Sumtree' (#702)
* beginning to remove sum

* continuing to remove sumtree sums

* finished removing sums from pmmr core

* renamed sumtree files, and completed changes+test updates in core and store

* updating grin/chain to include removelogs

* integration of flatfile structure, changes to chain/sumtree to start using them

* tests on chain, core and store passing

* cleaning up api and tests

* formatting

* flatfiles stored as part of PMMR backend instead

* all compiling and tests running

* documentation

* added remove + pruning to flatfiles

* remove unneeded enum

* adding sumtree root struct
2018-02-22 13:45:13 +00:00
Ignotus Peverell
3b51ffd83c
Fixup MMR position in n_leaves if invalid
Allows the client to not worry about what position is a valid
MMR size. Associated tests.
2018-02-20 21:48:24 +00:00
Ignotus Peverell
866ec977da
Factoring in mmr leaf count function 2018-02-19 23:20:32 +00:00
Yeastplume
c63aa70a0b
Integrated bulletproofs into Grin with optional build parameter (enabled by default) (#711) 2018-02-16 20:34:54 +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
8bdf0be73e
compact block needs a random nonce in it (used to generate short_ids) (#709) 2018-02-14 09:19:24 -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
Antioch Peverell
ad594b53de
Revert "add block validation consensus rule for block coinbase output" (#691)
also fix tests for size of blocks etc.

This reverts commit ecda870d70.
2018-02-07 12:23:48 -05: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
Antioch Peverell
62e44fa936
[WIP] Kernel investigation (#679)
* add some tests around building a tx_kernel from a tx
and adding secret keys together (and checking commitments)

* key addition tests
2018-02-02 09:51:55 -05:00
Antioch Peverell
5fe06e3e3b
we can now hydrate empty compact blocks and process them (#675)
* we can now hydrate empty compact blocks and process them

* add some tests to verify size of
various serialized blocks and compact blocks

* add_test_hydrate_empty_block

* fix broken test
2018-02-01 16:40:55 -05:00
Quentin Le Sceller
1e50d56c7e Add unit tests for API Endpoint (#653)
* First tests for API handlers

* Test chain UTXO handler

* Add test sumtrees handlers

* Fix typo

* Removed unused logger

* Update bitflags to ^1.0

* Missing test for bitflags update

* Moved test to grin directory

* Remove tests dependencies

* Add API P2P tests

* Fix hex string commitment

* Fix conflicting port

* Fix directory conflict and server port

* Wait for at least one block is mined on Travis
2018-02-01 13:14:32 -05:00
Antioch Peverell
e86de901fb block.merge() is unused (and misleading) (#674) 2018-01-31 21:58:41 +00:00
Antioch Peverell
c75026153c
only include kern_ids in compact block (we can safely omit input and outputs ids) (#670) 2018-01-31 10:23:42 -05:00
Yeastplume
f288a18b0c
minor test fix (#669) 2018-01-31 10:56:41 +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
Antioch Peverell
84128964fa Add test to cover case where a block has no coinbase outputs or kernels (#656) 2018-01-26 22:35:58 +00:00
Antioch Peverell
5a7d22977e
refactor/rework key derivation (#652)
seed -> ext_key -> many child_keys
2018-01-25 15:19:32 -05: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
92d0fc3c08 Add block validation consensus rule for block coinbase output (#647)
and kernel counts
2018-01-22 20:55:27 +00:00
AntiochP
ba4c450d2f
coinbase output(s) and kernel(s) always full in compact block (#641)
all other tx inputs/outputs/kernels can be reduced to their short_ids
2018-01-19 22:29:48 -05:00
AntiochP
9085e548f7
ShortId implementation (and CompactBlock) (#637)
* [wip] short_id implementation (first attempt)
todo - make this more reusable (a trait?) so we can use it for inputs/outputs/kernels easily

* factor short_id support out into ShortIdentifiable trait

* block can now be converted to compact_block
rename existing block.compact() -> block.cut_through()

* expose compact block representation via block api endpoint
optional with ?compact query param
2018-01-19 17:43:02 -05:00
Yeastplume
f9726e8154
Mining/POW Updates (#639)
* large updates for mining, fix async mode, will list changes in PR

* reset config and build defaults
2018-01-19 17:48:18 +00:00
AntiochP
6b0f1fc20e
summing two sum_commits rolls the switch commit hashes up (#634) 2018-01-18 17:25:10 -05:00
AntiochP
f1bbf5370e
add switch_commit_hash back into sum_commit (#630) 2018-01-18 10:53:54 -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
Yeastplume
9704cc35bd Aggsig Serialization (#618)
* changing ser of aggsig signature
* serialise Signature as raw 64 bytes
* remove compact sig
* remove to_compact
* remove unused import
2018-01-15 20:45:26 +00: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
Ignotus Peverell
a7044307f2
One grin per second, fixes #569 2018-01-07 04:21:50 +00:00
AntiochP
33c8e73403
maintain switch_commit_hashes in the output pmmr (not used yet) (#583) 2018-01-06 22:18:12 -05:00
AntiochP
26c2669fe8
pmmr should not depend on switch_commit_hash to identify utxo (#576)
* pmmr does not depend on switch_commit_hash
for a given chain a commitment shold be sufficient to identify a utxo

* fix the tests
2018-01-04 13:38:46 -05:00
AntiochP
4ba453694d
fix - sort tx inputs/outputs (#533) (#542)
* added debug logging to see what we're doing in save_pos_index

* add counts to logging

* make sure inputs/outputs in tx are sorted
tweak debug logging

* DRY up sorting of inputs/outputs/kernels via a simple sort() in ser/deser

* add explicit validation fo sort order during tx and block validation

* sort order consensus rule for inputs/outputs/kernels in blocks

* we want a max of 10*num_peers blocks during sync...
not min

* fix test imports
2017-12-22 12:15:44 -05:00
Ignotus Peverell
be094883de Improved fix for MMR dup detection 2017-12-14 01:13:04 +01: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
Simon B
fed0bd3ed3 [CONSENSUS] Limit number of inputs in a block #261 (#328)
* Limit number of inputs in a block, fix #261
* MAX_BLOCK_INPUTS = 300_000 // IO-time bound DoS protection. 5MB/s disk random reads gives ~150k UTXO lookups/s, so set limit at 300k UTXO inputs
2017-11-19 19:59:07 -05:00
Yeastplume
4b3a374d98
Wallet Restore feature (#338)
* beginning to add wallet restore... api endpoints and basic restore

* basic restore working, still missing features

* rustfmt

* large speed up to output search, should be more or less working

* properly mark coinbase status
2017-11-20 00:50:09 +00:00
Ignotus Peverell
fec8858ead
Ported acbe983 and 58d7dc7 from testnet1 branch 2017-11-16 18:17:56 -05:00
Ignotus Peverell
97d7a43ccf
Default value for ChainType, when not in grin.toml 2017-11-15 17:30:48 -05: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
10a1ddf5e8 Use consensus rule that minimum difficulty is 10 (#251) 2017-11-13 19:45:10 -05:00
AntiochP
596bbd9b6e
add premined pow solution for cuckoo16/UserTesting (#260)
* add premined pow solution for cuckoo16/UserTesting
faster startup time

* only check premined solution on genesis block (height 0)
2017-11-13 10:24:49 -05:00
AntiochP
c1656f7660
use the static secp instance everywhere (except the wallet) (#250) 2017-11-09 14:26:45 -05:00
Yeastplume
1eeb1fae22
Wallet amounts (#241)
* allow selecting a commit while providing a key index

* misnamed variable

* added static reference to libsecp that can be called throughout

* don't serialise rangeproof to json if it's not desired

* forgotten new file

* amounts input and displayed in wallet are now in full grins, with optional decimal place

* rustfmt

* merge branch

* better acknowledgement of transaction being sent
2017-11-07 21:20:36 +00:00
Yeastplume
48a60858ba Wallet output selection performance (#238)
* allow selecting a commit while providing a key index
* added static reference to libsecp that can be called throughout
* don't serialise rangeproof to json if it's not desired
2017-11-07 11:48:37 -05:00
AntiochP
ad07866275 iterate once over txs in a block (#233)
Split out verify_sig and build_kernel to make kernel explicit.
2017-11-03 14:17:09 -04:00
Ignotus Peverell
dbaba8aed5
Order block elements when block is built 2017-11-01 22:18:51 -04:00
Ignotus Peverell
5b462ee2fc
Allowing for dumping of larger sum trees on error 2017-11-01 19:32:49 -04:00
Ignotus Peverell
f7ddd6b3d3
Fix couple minor import errors after rebase 2017-10-31 20:00:39 -04: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
Yeastplume
914810713d Add test for switch commit consistency (#219) 2017-10-31 17:20:11 -04:00
Yeastplume
7f8d307cc8 Sum tree and improved chain API Endpoints (#214)
* adding more useful handlers
* added method to return last n leaf nodes inserted into the sum tree
* endpoints in place for getting last n sumtree nodes
2017-10-27 21:57:04 +00:00
AntiochP
7178b400b8 refresh multiple wallet outputs in single api call (#205)
* mount v2 router for flexibility - wallet checker now refreshes multiple outputs via single api call
* fix the api router
2017-10-25 17:57:48 +00:00
Ignotus Peverell
f679a9e458
Consensus change: set reward and base grin unit 2017-10-22 10:56:55 +00:00
Ignotus Peverell
f1488f9529
Lots of chain sync and block validation fixes
* Fix for the chain pipeline partly relying on an outdated head,
leading to not properly recognizing a fork and inconsistent sum
tree state.
* Do not drop block requests during sync that don't get satisfied,
retry enough time to get them and avoid stall.
* Always validate header, even in sync where we may have validated
it already. We don't want a block coming from a peer that could
squeeze through with an invalid header.
* When syncing, do not mark blocks that were errored by the chain
as received (typical case: orphan). Keep retrying.
* Improved chain state dump for debugging.
* Do not add to orphans blocks too far in the future.
* Better error reporting on db errors.
* Related sync test fixes.

TODO figure out why syncing peers timeout so often, very useful
to test but not that great for a fast sync experience.
2017-10-22 07:11:45 +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
9a230ca7f6 fail deserialization if inputs or outputs are not sorted for txs (#173)
* fail deserialization if input or outputs are not sorted for txs, fail deserialization if inputs or outputs or kernels are not sorted for blocks, make sure we sort them before serialization
* extract consensus rule into verify_sort_order on VerifySortOrder trait
* rework the sort and write into WriteableSorted trait
* fix wallet sending bug (fees related) so we can test
* refactored read_and_verify_ordered out into ser, used in transaction and block
2017-10-13 17:23:18 +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
Ignotus Peverell
b85006ebe5 Wallet operation to burn some coins (#172)
* Burn transaction for testing
* Burn bug fixes, embed burn key in keychain
* Better error logging in API, wallet fee calc fix
2017-10-12 03:35:40 +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
Ignotus Peverell
9310151680
Block versions and hard fork schedule 2017-10-10 00:09:06 +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
Ignotus Peverell
c7f1ce965e
Block size limit as a max weight 2017-10-06 03:35:06 +00:00
Ignotus Peverell
7012d37f5f
Half of fees get rewarded, half burnt. Minor cleanups
Update coinbase building and block summation to account for half of
the fees going to the coinbase. Forcing fees to be even as a
consequence. Now that we can't build the coinbase independently
from the block (because fees), had to update the miner to keep the
key derivation so a new derivation isn't made any time a new block
gets worked on.

Minor doc and warning cleanups.
2017-10-05 07:30:10 +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
Ignotus Peverell
4e49b85b82
Cleanup for block validation errors 2017-10-03 22:27:26 +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
6b4f2a63da
Store test for sumtree rewind 2017-10-02 22:32:45 +00:00
Ignotus Peverell
8504efb796
Cargo fmt all the things 2017-09-29 18:44:25 +00:00
Ignotus Peverell
0a57258d42
Fix #144 with platform specific import. Add store crate to CI 2017-09-29 18:09:44 +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
0b26a57ca6 Remove rust-crypto dependency (#141)
Use blake2b in wallet for key derivation and key identifiers
2017-09-26 22:51:45 +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
dbc4e10cec Wallet now supports coinbase maturity (#130) 2017-09-22 16:44:12 +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
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
osaka-kun
6493468959 Checking rangeproof explanatory comment (#120) 2017-09-12 17:20:26 +00:00
AntiochP
4aea4d0548 fixes to allow benchmarks to be run for core (#122)
cargo +nightly bench -p grin_core
2017-09-12 17:20:01 +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
Ignotus Peverell
405a4bc985 Prunable MMR storage (#112)
* Base MMR storage structures

Implementations of the MMR append-only file structure and its
remove log. The append-only file is backed by a mmap for read
access. The remove log is stored in memory for quick checking
and backed by a simple file to persist it.
* Add PMMR backend buffer, make PMMR Backend mutable
* The Backend trait now has &mut self methods, and an &mut
reference in PMMR. This simplifies the implementation of all
backends by not forcing them to be interior mutable. Slight
drawback is that a backend can't be used directly as long as it's
used by a PMMR instance.
* Introduced a buffer in the PMMR persistent backend to allow
reads before the underlying files are fully flushed. Implemented
with a temporary VecBackend.
* Implement a prune list to use with dense backends
The PruneList is useful when implementing compact backends for a PMMR (for
example a single large byte array or a file). As nodes get pruned and
removed from the backend to free space, the backend will get more compact
but positions of a node within the PMMR will not match positions in the
backend storage anymore. The PruneList accounts for that mismatch and does
the position translation.
* PMMR store compaction
Implement actual pruning of the underlying PMMR storage by
flushing the remove log. This triggers a rewrite of the PMMR nodes
data (hashes and sums), removing pruned nodes. The information of
what has been removed is kept in a prune list and the remove log
is truncated.
* PMMR store pruning tests and fixes
2017-09-05 05:50:25 +00:00
AntiochP
7b12746a1f Store block header hash by input and output commitment (#104)
* initial pass at indexing block header hashes by commitments
* check block height matches currently indexed block height
when getting block header for an output commit
* add some test coverage
* document get_block_header_by_output_commit
2017-08-29 16:32:45 +00:00
Yeastplume
b5e62c81c0 Switch commitments in libsecp fork (#109)
* first pass at switch committment generator
* create sage generator script
2017-08-29 16:27:01 +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
babb6110c4 unit tests for coinbase flags (output and tx kernel) (#99)
* add tests around flipping COINBASE_OUTPUT and COINBASE_KERNEL flags
* add serialize_deserialize test for a minimal block
2017-08-22 18:26:13 +00:00
Yeastplume
045f5bb4da POW refactor (#100)
* Adding output stats from plugin, when available
* adding grin config
* moving pow crate from core/pow to it's own crate
* moving POW/mining stuff into pow module, and removing mining dependency from chain
* refactored most of mining into pow module...miner.rs still in server
* update grin tests
* updating genesis block mining to use configured miner, if available
* chain tests back into chain, done with pow refactor
* use tag of cuckoo-miner for pr
2017-08-22 18:23:54 +00:00
Riccardo Casatta
6772d9f516 various typos in docs (#95)
* various typos in docs
* fix a number in comments
2017-08-21 16:56:26 +00:00
Yeastplume
2a275a2f87 POW Blake 2 changeover (#91)
* playing around with changing cuckoo sizes on the fly
* modifying tests to use global cuckoo parameters, and checking results
* check for pow size
* Changing global function names, and removing length from POW serialization
* changes to use blake2 for cuckoo seed generation
* updating tests to blake 2
2017-08-11 21:05:59 +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
Yeastplume
131ea2f799 Ci mode fixes (#86)
* playing around with changing cuckoo sizes on the fly
* modifying tests to use global cuckoo parameters, and checking results
* check for pow size
* Changing global function names, and removing length from POW serialization
2017-08-09 16:40:23 +00:00
Ignotus Peverell
d32ab967f0
Prunable and easy to store MMR impl 2017-08-05 09:32:41 +00:00
Ignotus Peverell
ae9a9c8938
Merge branch 'master' of github.com:ignopeverell/grin 2017-08-04 19:52:04 +00:00
Ignotus Peverell
95fe570187
Prunable and easy to store MMR impl 2017-08-04 19:50:32 +00:00
Yeastplume
cdf4203dd1 Cuckoo miner integration, Queue implementation (#84)
* Adding ability to serialise parts of the header, pre-nonce and post-nonce
* Some test integration of queueing functions in cuckoo-miner
* more cuckoo-miner async mode integration, now more or less working
* integrating async miner workflow
* rocksdb update
* u64 internal difficulty representation, and integration of latest Cuckoo-miner API
* change to cuckoo-miner notify function
* Issue in testing, and if use_async value is None in grin.toml
* making async mode explicit in tests - 2
* fiddle with port numbers for CI
* update tag to ensure cuckoo-miner build doesn't fail on windows
* change the order in which tests are run
2017-08-03 16:57:55 +00:00
Ignotus Peverell
a6047903d2
Sum tree: n_children -> n_leaves (more explicit) 2017-07-24 21:46:22 +00:00
Ignotus Peverell
22f3d42b94
Simple sum tree benchmark 2017-07-23 01:19:10 +00:00
Ignotus Peverell
2261415c27
Oops. Fix blake2 dependency issues. 2017-07-20 15:03:47 +00:00
Ignotus Peverell
eb11b14cab
Minor warning cleanup in core
Remove some unused import and add missing docs.
2017-07-20 14:22:40 +00:00
Ignotus Peverell
929943d8b1
Sum-tree only stores hashes
Couple improvements to the sum tree implementation. First change
is to not store the data but only its hashes, assuming a higher
level layer will take care of the data (KV store).

Second minor improvement is renaming Node into NodeData and vice
versa.
2017-07-20 14:07:57 +00:00
Ignotus Peverell
01b66de437
Replace SHA3 with BLAKE2b everywhere 2017-07-20 13:52:33 +00:00
Ignotus Peverell
9703cba92a
Formatting 2017-07-20 13:52:33 +00:00
Yeastplume
42376e68bc Cuckoo-miner better merged into Grin (#80)
* Adding cuckoo-miner into grin as a proper dependency now
* Defaulting to using cuckoo-miner
* Updates to tests to use cuckoo_miner by default, (using cuckoo16)
2017-07-18 20:57:09 +00:00
Merope Riddle
e2ebd854e1 [WIP] Implement Merkle-sum-tree (#40)
* core: partially implement sumtree; appending and pruning work
* core: add simple merkle-root-sum-calculating function. 
* core: implement replacement in sumtree
* core: implement de/serialization for sumtree
* core: make sumtree index use hashes rather than data
* core: prevent double-adds to sumtrees
* core: replace sumtree's separate sums with a Summable trait
* core: make SumTree::contains() return the index if an element exists
2017-07-12 18:59:18 +00:00
Yeastplume
12480e7310 Changes to allow for testing and playing with cuckoo-miner integration (#76)
* Refactoring to allow for different miner implementations. Added conditional support for compiling and loading the cuckoo-miner plugin project.
* Small changes to experimentally integrate with cuckoo-miner and compatibility with latest version of cuckoo-miner.
* Turning off inclusion of cuckoo_miner by default
* Disabling simulate_parallel_mining test for now
2017-07-11 17:11:03 +00:00
Yeastplume
97b7421ce0 Mining test debug output, fixes to diff. adjustment and start of POW documentation (#69)
* Beginning to add a POW description, and some minor changes to mining testing, addition of further debug information to mining output.
* Many additions to create first draft of POW documentation
* Fixes to difficult adjustments by adding a MINIMUM_DIFFICULTY consensus value. Otherwise never adjusted above 1 due to flooring.
2017-06-29 16:49:11 +02:00
Ignotus Peverell
75f19ecfab
Fix difficulty tests, forgot to rename method 2017-06-20 10:21:31 -07:00
Ignotus Peverell
e8a6b61100
Apply new difficulty algo, remove configurable cuckoo size
Integrate the new difficulty calculation into the block chain
validation, the miner and tests. As the difficulty calculation
doesn't use varying Cuckoo sizes anymore and we narrowed down
reasonable final Cuckoo Cycle parameters, removed all Cuckoo
Cycle sizes from block headers.

Formalized easier Cuckoo Cycle sizes for testing (and possibly
testnet) by introducing a test mode in configuration. Updated
all tests.
2017-06-19 08:59:56 -07:00
Ignotus Peverell
163b1133a7
Implemented new difficulty calculation algorithm.
See #62 for background. Still needs to be integrated with proof
of work and validation.
2017-06-17 20:22:20 -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
11c0d67805
Revert "Delegate Block Encoding to Store (#44)"
This reverts commit 8ffc0c6f8e.
2017-05-31 15:49:15 -07:00
Ignotus Peverell
40d23db6c1
Revert "[WIP] Partial Transition from Writeable/Readable to Codecs (#51)"
This reverts commit de4ebdde71.
2017-05-31 15:47:52 -07:00
Ignotus Peverell
996eab72ae
Formatting. 2017-05-31 14:44:44 -07:00
Ignotus Peverell
f79fb8ef95
Sending end of the wallet
Most of the logic to build a transaction that sends coin to
another party. Still requires more debugging and clean up.
Main changes and additions are:

* Update to serde 1.0
* API endpoint to retrieve an Output
* Output is now Serialize and Deserialize
* Wallet configuration
* Command line for the send operation
* Wallet data checker to update created outputs into confirmed
* Wallet-specific configuration
2017-05-28 20:21:29 -07:00
Ignotus Peverell
1ae2e905d8
Printing difficulty while mining 2017-05-25 17:42:29 -07:00
Ignotus Peverell
791d2355ee
Miner querying wallet receiver for coinbase output
With the coinbase receiver daemon in place, when starting a Grin
server in mining mode, the miner will now ask the receiver for a
coinbase output. The output is then used to insert in a block when
successfully mined.
2017-05-25 17:22:21 -07:00
Ignotus Peverell
ac553493f1
WIP: Wallet functionality to receive and send coins
Beginning of a first pass at simple wallet functionalities so
Grin can be used to author transactions. We introduce a
receiving server, to be at least able to build coinbase outputs
that can be used by the mining daemon.

Present:

* Coinbase receiving API.
* Command to start the receiving server.
* Beginning of a transaction sending command.
* Improvements to the REST API abstractions to support the above.

Still to do:

* Change to the miner daemon to use the receiving server.
* A command line sender.
* API to receive any transaction (not just coinbase).
* A command line receiver.

Beyond that, HD derivation and seed generation are very simple
so far and almost certainly insecure. Just for testing for now.
2017-05-24 16:09:39 -07:00
Jacob Payne
de4ebdde71 [WIP] Partial Transition from Writeable/Readable to Codecs (#51)
* Sample Signatures for put_enc and get_dec
* Implement put_enc and get_dec
* Implement ChainCodec in grin_chain
* Truncate src only on complete Blocks
* Truncate src only on complete Tip + Check Len
* Move BlockHeader Encoding to BlockHeaderCodec
* Define put_enc for store::Batch
* Replace BlockCodec and BlockHeaderCodec with generic BlockCodec<T>
* Implement Default for BlockCodec Manually
* Replace get_ser/put_ser with get_enc/get_dec for chain::ChainKVStore
* Remove Writeable/Readable for chain::Tip
* Add Tokio-io and Bytes to grin_p2p
* Additional Setup for Message enum + Msg{Encode,Decode} traits
* base msg ping pong encoding and test
* fill out msg-codec tests
* Implement Hand Encoding/Decoding
* msg-encode shake
* msg-encode getpeeraddr
* codec peer-addrs message, SockAddr struct wierdness
* header message codec
* msg encoding finished prelim
* Implement PeerCodec Encoding/Decoding
* Set PeerStore to use PeerCodec for Encoding/Decoding
* Add a DecIterator
* Prune PeerStore
* Replace Decoding and Encoding in handle_payload
* Prune Writeable/Readable methods in store::Store
* Remove Incomplete Frame Testing ( Not Nessesary right now )
* separate block and tx codec tests
* Refactor {Tx,Block}Codec Tests
2017-05-22 19:16:13 +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
Jacob Payne
8ffc0c6f8e Delegate Block Encoding to Store (#44)
Builds codecs to encode and decode blocks, block headers, transactions, kernels, etc. Will be used by the store and peer-to-peer layer for serialization, but also to compute hashes. Separates out serialization from core.
2017-05-03 10:27:38 -07:00
Ignotus Peverell
e4ca924b47
Various comment and dead wood cleanup 2017-04-20 11:31:02 -07:00
Ignotus Peverell
e71ae27f77
Invert inputs and outputs commitment sums. Fixes #37. 2017-04-10 00:27:19 -07:00
Merope Riddle
39ddeb0a2a core: various cleanups, improvements, code comments (#38)
* core: cleanup slicing impls for Hash
* core: clean up Readable trait, implement Readable/Writeable for various integers
* core: change Hash debug output to hex
* core: correct warnings in all modules
2017-04-09 23:17:23 -07:00
Jacob Payne
9e82fb1774 Replace AsFixedBytes with Sized + AsRef<[u8]> (#35)
* Replace AsFixedBytes with Sized + AsRef<[u8]>
* Add AsRef<u8> to impl_array_newtype!
* Include AsFixedBytes as marker trait
* Related fixes
* Remove Deref
2017-04-06 22:54:54 -07:00
Ignotus Peverell
382754e54c
Add workspace support for all crates 2017-04-05 23:41:49 -07:00
Ignotus Peverell
afb219ce5c
Hashed impl only needed for empty arrays. 2017-04-03 18:10:55 -07:00
Ignotus Peverell
38d5d67e79
Add features bitmask to Block, Output, Kernel; coinbase validation
Block, Output and Kernel now have bitmasks to hold supported
features and eventually versioning. Will make adding features and
updates easier and open the possibility of soft forks.

First added feature for Output and Kernel is the marking of coinbase
related ones. Allows the validation of the coinbase part of a block.
2017-03-23 17:06:00 -07:00
Ignotus Peverell
b6b815f6c1
Reintroduce block tests with new tx building
The build module introduced some facilities to build transactions
that can now be leveraged when building blocks and in related
tests.
2017-03-20 14:32:11 -07:00
Ignotus Peverell
6bd3fc0d48
Cleanup of Transaction and Block data structures
Some renaming and cleanup of the Input, Output, Transaction and
Block structs. The main change is the removal of all the overt
structures which are now replaced by a specialized module to
build transactions easily. More specifically:

* Rename the TxProof to TxKernel in Block to reflect the current
naming consensus in MimbleWimble.
* Change Input and Output to be plain structs instead of enums
making their manipulation a lot easier. The building of
transactions is now handled by the build module.
* Input now directly includes the commitment of the Output it's
spending instead of going through an intermediate hash.
* The new build module encapsulates all the transaction building
logic, making it very straightforward by chaining combinators.
* Moves some tests to the core mod.rs as they required being able
to build a transaction to test it.
2017-03-20 14:07:00 -07:00
Ignotus Peverell
cb84f588fb
Small tweaks and addition to a Transaction to make 2-parts building easier. Unit test covering the standard exchange between 2 parties when building a transaction. 2017-03-11 13:48:33 -08:00
Ignotus Peverell
f64d20749f
Framework to define services as RESTful HTTP API services. Serde implementations for some core types. 2017-03-07 17:00:34 -08:00
Ignotus Peverell
45b134ab30
PoW only ever needs the block header, full block unnecessary. 2017-02-07 13:48:11 -08:00
Ignotus Peverell
dde54beb3f
Hash needs to be writeable for network serialization. 2017-02-06 12:08:35 -08:00
Ignotus Peverell
4a034018cb
Block inputs and ouputs Merkle tree validation. 2017-01-25 11:44:37 -08:00
Ignotus Peverell
dda223f25b
Chain logic to support multiple forks, select the most worked fork as the head. Significantly simplified from the original direction as it doesn't seem that explicitly materializing forks is necessary. Simple total difficulty accounting in block headers helping a lot there. 2017-01-09 15:16:44 -08:00
Ignotus Peverell
85e3255ee4
Removed need for a PowHeader. Directly checking serialization mode in block header serialization instead. 2017-01-09 12:07:38 -08:00
Ignotus Peverell
ce23dda6cb
Block headers maintain total difficulty up to previous. Changed all references of target to difficulty to stay consistent. Ported retargeting algo to use difficulty as well. 2016-12-26 15:39:31 -08:00
Ignotus Peverell
c1340223de
Minor API change to PoW verify, to use the size provided by the block header by default. 2016-12-20 17:32:19 -08:00
GarrickOllivander
2e6d3d9fdb Safer serialization of base types (#18)
* use MESSAGE_SIZE constant instead of 32
* use Hashed trait in genesis
* safer serialization of Hash
* Hashed of [u8] should send only data to hash function, not length + data
* Safer serialization of Proof
* Safer serialization of Commitment
* Safer serialization of RangeProof
* introduce read_limited_vec instead of potential panic in conversion
2016-12-17 13:44:14 -08:00
Ignotus Peverell
d395b3d128
Added another server implementation for when the client needs to stay in control of the event loop (i.e. multiple servers for tests). Test to spin up 5 servers and connect them all together. 2016-12-14 16:10:39 -08:00
Ignotus Peverell
8a255c0218
Formatting. 2016-12-13 19:21:49 -08:00
Ignotus Peverell
4b5c010b05
Rewrote most of p2p code to use futures-rs instead of mioco. Need some cleanup and support for a few more message types. 2016-12-10 19:11:49 -08:00
Ignotus Peverell
eb56d40807
Removed limit on number of inputs or outputs in blocks and transactions. For DoS protection only a total message size needs to be enforced by the p2p layer. 2016-12-07 18:54:28 -08:00
Ignotus Peverell
4d7bc2269b
Fixed retargeting tests for truncation. 2016-11-30 11:15:49 -08:00
Ignotus Peverell
ea1820cff7
Fixed usages of block constructor. 2016-11-30 11:15:23 -08:00
Ignotus Peverell
55f5771a2a
Avoid unecessary move of the previous block header to build a block. 2016-11-29 20:05:35 -08:00
Ignotus Peverell
2e52b13c35
Date format uses year since 1900. 2016-11-29 20:04:13 -08:00
Ignotus Peverell
1ab9001338
Target needs to be truncated after next target calculation, given that serialization in the block header does it anyway. 2016-11-29 20:03:43 -08:00
Ignotus Peverell
11b8a6222a
Any size pow accesible to tests. 2016-11-29 18:46:28 -08:00
Ignotus Peverell
d11c85dae1
Fixed missing previous in block header. 2016-11-29 18:42:43 -08:00
Ignotus Peverell
9795d9e452
Miner facility, using the current chain state to build on top of. 2016-11-27 12:31:15 -08:00
Ignotus Peverell
ca26f0c3f7
Block header needs its own deserialization. Fixed pow verify to use the block target. 2016-11-16 14:08:46 -08:00
Ignotus Peverell
3c5e2b2958
Block now uses the new Target type. Consensus next_target calculation adjusting every block based on deviation and increasing Cuckoo size gradually. Block time of a minute until we learn more from mining ecosystem, so enough PoW attempts can be made even on CPUs. 2016-11-15 14:41:16 -08:00
Ignotus Peverell
44545525f4
Target addition and subtraction. A little more doc. 2016-11-15 14:41:16 -08:00
Roman Zeyde
151a0150b9 Fix a small typo in documentation 2016-11-14 21:21:18 +02:00
Ignotus Peverell
f7b31dc5f3
Bitcoin-style target implementation. Large 32 byte number that can be compared and serializes truncated. 2016-11-13 21:04:01 -08:00
Garrick Ollivander
956dd6b816
fix file headers: Developer -> Grin Developer 2016-11-13 12:47:09 +01:00
Ignotus Peverell
2b8faf8709
A few more consensus values. 2016-11-10 17:19:03 -08:00
Ignotus Peverell
d710301833
Missing consensus file. 2016-11-10 16:02:47 -08:00
Ignotus Peverell
baeae7d1a5
Merged master. 2016-11-10 15:54:47 -08:00
Ignotus Peverell
4ade3ec1b8
Moved consensus related constants to their own core module. 2016-11-09 15:51:24 -08:00
Ignotus Peverell
6e2a232ca3
Cleaned up total fees from block header. Unnecessary now. 2016-11-09 13:25:40 -08:00
Ignotus Peverell
4e9aad639e
Formatting fixes. 2016-11-09 11:10:02 -08:00
Ignotus Peverell
8317854b70
Slight changes to transaction signature. The transaction fee gets signed (instead of the empty string) and the fee amount is attached to the transaction proof in blocks. This allows fee accounting and the tracking of fees within a block. 2016-11-09 11:05:44 -08:00
Ignotus Peverell
ea425dc614
Protocol cleanup. Tests cleanup. Additional test for transaction broadcast. 2016-11-05 16:31:45 -07:00
Ignotus Peverell
edc6c62577
Fixed message serialization following changes in core. Sending of block and transaction. 2016-11-01 10:42:33 -07:00
Merope Riddle
33ccfe3b65 core: remove several unused imports 2016-11-01 13:19:38 +00:00
Merope Riddle
ca89dae7e1 core: unify Hashed and Writeable to simplify things and remove allocations 2016-11-01 13:19:28 +00:00
Merope Riddle
245f0a8b56 core/ser: add default implementations for most methods of Writer 2016-11-01 13:14:26 +00:00
Merope Riddle
630c4eb6fb core/ser: replace write_vec with write_bytes, drop a bunch of clones 2016-11-01 02:14:52 +00:00
Merope Riddle
bc38016385 core/ser: change serialization trait to use Result<(), Error> in place of Option<Error> 2016-11-01 02:14:52 +00:00
Ignotus Peverell
2efa8ce706 Merge pull request #7 from GarrickOllivander/fix_merkle_tree_malleability
Fix Merkle tree malleability.
2016-10-30 18:18:40 -07:00
Ignotus Peverell
42769c373c
Re-implemented the whole interaction between server, peer and protocol to be more Rust-ish. Server maintains peer references and protocol is internally mutable. 2016-10-29 12:36:45 -07:00
Garrick Ollivander
4e11aab1ea
added comment to avoid this vulnarability sneaking back 2016-10-29 18:18:32 +02:00
Garrick Ollivander
ab3ffafdcd
fix merkle tree malleability 2016-10-29 17:55:47 +02:00
Ignotus Peverell
b1762cb5f4
p2p module getting close to first integration test allowing 2 peers to connect. Fleshed out handshake and protocol use. Fixed most errors, just need to make the borrow checker happy. 2016-10-25 22:06:13 -07:00
Ignotus Peverell
4657b09c4e
WIP: more p2p code, mostly interaction between peer, protocol and server as well as ser/deser for first message types. 2016-10-24 21:35:10 -07:00
Ignotus Peverell
9f780f6865
Converse of deser macro to make serialization of structs less verbose. 2016-10-24 20:41:28 -07:00
Ignotus Peverell
b50e1ab038
Simple macro to remove some of the verbosity in deserialization. 2016-10-24 17:43:14 -07:00
Merope Riddle
4b51610d9a core: move remaining contents of core/ser.rs into ser.rs 2016-10-23 19:50:58 +00:00
Merope Riddle
82adc54971 core: separate Transaction into its own module 2016-10-23 19:49:35 +00:00
Merope Riddle
2ea58d4478 core: move Block and BlockHeader into their own module 2016-10-23 13:53:29 +00:00
Merope Riddle
88b07791fa core: move Hash into its own module 2016-10-23 13:23:04 +00:00
Merope Riddle
7e2b271865 add doccomments for consensus comments 2016-10-23 13:23:04 +00:00
Merope Riddle
9644fb6a73 Add apache 2.0 license header to all source files 2016-10-23 13:20:39 +00:00
Ignotus Peverell
e5e908adde Merge pull request #1 from kanzure/trivial-typo-fixes
Fix some trivial typos
2016-10-22 00:47:20 -04:00
Ignotus Peverell
d3e4ecc100
Corrected spelling of Cuckoo Cycle here and there and updated easiness to 50% following @tromp feedback. 2016-10-21 18:02:20 -04:00
Bryan Bishop
2fff216491
fix some trivial typos 2016-10-21 10:17:33 -05:00
Ignotus Peverell
f73a308bf3
Initial import. 2016-10-20 20:06:12 -04:00