Commit graph

454 commits

Author SHA1 Message Date
Ignotus Peverell
8e2b0c7bc8
Bump version to 1.0.2 (#2623) 2019-02-24 21:57:56 -08:00
Yeastplume
ea4b4fc389
Remove wallet code [1.1.0] (#2593)
* Bump version to 1.1.0

* remove wallet crate

* wallet extracted + mine_block structs

* remove wallet doc

* remove unnecessary cargo deps

* rustfmt

* remove wallet from travis matrix

* move integration tests into separate crate

* rustfmt

* move integration crate to wallet
2019-02-21 11:57:45 +00:00
Antioch Peverell
23cb9e2514
Map peers by ip only (ignoring port unless on loopback ip) (#2540)
* wip

* big refactor, regretting doing this now

* PeerAddr everywhere

* cleanup

* fixup server tests

* peers api working for GET, POST is still WIP

* we can now ban/unban peers by ip only (port optional)
2019-02-18 12:15:32 +00:00
Jeremy Rubin
41ed10940d fix: Fix race condition with dandelion_relay peer map and make more semantic (#2548)
* fix: Fix race condition with dandelion_relay peer map and make more semantic

* Fix bug where we don't actually re-read the dandelion_relay variable after refreshing it
2019-02-13 10:40:31 -08:00
hashmap
a63cfa7138 Allow to have more than min_peers/2 outbound peers (#2537)
* Allow to have more than min_peers/2 outbound peers

Default value is 8, so we allow only 4 outbound peers, unfortunately if a node is behind NAT it can't get inbound peers and it stucks with 4 peers as maximum.
This PR allows a number of outbound peers to be between min_peers and max_peers/2. Node behind NAT will eventually have just min_peers number of peers.

* Extract into healthy_peers_mix function
2019-02-07 12:26:23 -08:00
Antioch Peverell
19ce9cc28e
bump for v1.0.1 (#2511) 2019-02-01 14:43:18 +00:00
Antioch Peverell
a82e2a0126
Rework "bucket transactions" logic (buckets are now weight limited) (#2487)
* rework bucket txs

* introduce max_block_weight to global (based on chain_type)
not yet in use anywhere...

* now using global::max_block_weight() everywhere

* testing max_block_weight needs to be big enough to cover existing chain tests...

* add some test coverage for prepare mineable transactions at the block weight limit
introduce AsLimitedTx{max_weight} so we can build artifically small blocks (per mining config)

* cleanup

* default_mineable_max_weight is just the default max_block_weight
we do not need to account for coinbase reward here (tx vs block)

* 75 change outputs in a test is not valid now that we have a low block weight limit...
2019-02-01 10:44:04 +00:00
Simon B
dd1a24dcbc Compiler warnings 20190123 (#2462)
* cleanup compiler warnings: unused imports

* rustfmt

* more compiler warnings
2019-01-25 10:09:32 +00:00
Antioch Peverell
ef5d83817e
Maintain min outbound peers (min_preferred_peers / 2) (#2417)
* outbound connection count

* rustfmt

* display outbound peer count

* rustfmt

* wip - allow connections to exceed max when trying to create new outcound connections
any in excess of total max will be cleaned up subsequently

* fix

* we care about connected outbound peer count when deciding to connect to new peers
2019-01-19 16:13:09 +00:00
Ignotus Peverell
e7485ab5f1
Version bump to 1.0.0 2019-01-15 16:24:29 +00:00
Ignotus Peverell
f9a20aef0d
Track blocks we requested, always broadcast otherwise (#2349) 2019-01-12 09:28:03 -08:00
Ignotus Peverell
5efcdbc077
Refuse duplicate peer IPs (#2347)
* Refuse duplicate peer IPs
* Explicitly mentioning NAT in code comment
* Well of course that would mess with tests. Only trigger using IP test when on the wild internet (~DNS seeding).
2019-01-11 15:51:38 -08:00
Gary Yu
7698b28e16
fix: wait_for_min_peers shouldn't wait forever when all peers are in same work (#2340) 2019-01-12 07:38:27 +08:00
Ignotus Peverell
1a6b46b09d
Ban peers that can't complete a handshake (#2320)
* Break out of main peer loop on error
* Force client conn shutdown on error
* Fix borrow error
* Ban peers that fail handshake
* Fix add_peer for ban, remove useless disconnect
2019-01-11 10:00:32 -08:00
Ignotus Peverell
60d3ee3c44
Bump version to 0.5.2 for release 2019-01-11 01:26:30 +00:00
Ignotus Peverell
f86c90ade5
rustfmt 2019-01-10 01:23:02 +00:00
Ignotus Peverell
6a244e904a
Fix add_peer for ban, remove useless disconnect 2019-01-10 01:22:48 +00:00
Ignotus Peverell
cf088f6f51
Ban peers that fail handshake 2019-01-09 20:31:09 +00:00
Ignotus Peverell
26d250bbea
Fix borrow error 2019-01-09 20:24:57 +00:00
Ignotus Peverell
7a44ee9aa0
Force client conn shutdown on error 2019-01-09 19:24:59 +00:00
Ignotus Peverell
684e8164f5
Break out of main peer loop on error 2019-01-09 19:14:50 +00:00
Ignotus Peverell
2c5ba853f7
Version bump to 0.5.1 2019-01-07 19:41:07 +00:00
Gary Yu
0b73e87f8c
fix: connection close should stay outside the poll loop (#2308) 2019-01-07 14:44:07 +08:00
Gary Yu
e79123fd5c
clean the unused p2p sockets (i.e. not in peers list) (#2298)
* clean the unused p2p sockets (i.e. not in peers list)

* add function comments
2019-01-07 14:41:41 +08:00
Gary Yu
6165c0873c fix: shutdown the tcpstream when we initiate to close a peer connection (#2288) 2019-01-04 09:08:44 -08:00
Gary Yu
7e8296dce0
fix: peer connect panic on log (#2272) 2019-01-02 09:54:17 +08:00
Gary Yu
23df6fa976
fix: check_banned must care about ip address only, and ignore the peer port info (#2267) 2019-01-01 11:43:05 +08:00
Yoni
972cea5fe9 more idiomatic way of picking the peer 2018-12-31 22:48:24 +02:00
Yoni
a5e5ae83b6 typo + styling 2018-12-31 20:00:33 +02:00
Yoni
b2cc5ba7e1 Enable setting a fixed dandelion peer 2018-12-31 18:49:05 +02:00
Gary Yu
738d49d560
fix: one peer occupy multiple tcp connections (#2262)
* shutdown the tcpstream when peer connect or accept fail

* remove the unnecessary 3 times retry on peer connecting

* connect/accept are actually handshakings instead of tcpstream connect/accept
2018-12-31 19:24:30 +08:00
Gary Yu
ea7eea3f84
Skip connecting PeerWithSelf by checking ip address (#2253)
* skip the connecting to self
2018-12-31 07:15:58 +08:00
Ignotus Peverell
9234e3c251
Re-launch floonet (#2249)
*  Fix secondary scaling bugs;  rename is_testnet -> is_floonet (#2215)
* add global::is_mainnet()
* use it to change pre-genesis pow type
* rename is_testnet -> is_floonet
* Support multiple chain configurations (#2217)
* Support multiple chain configurations
Supports generating the proper configuration for each chain type
(mainnet, floonet, usernet). Will run them by default under
their respective root directory (~/.grin/main, ~/.grin/floo, etc).
Assigned default ports for mainnet, overriding them to keep Floonet
ports unchanged.
For now, starting on mainnet will abort.
* Fixed usernet command line help message. Fixes #2217
* Differing magic numbers for each chain type (#2208)
* stick to e=H(R|P|m) when use schnorr signature (#2200)
* stick to e=H(R|P|m) when use schnorr signature
* (1)add verify_slate_messages for wallet receive (2)log the message content
* remove debug log on verify_slate_messages
* verify the sender's message signature when receive_tx in wallet listen
* Revert "remove debug log on verify_slate_messages"

This reverts commit 65ea32a407.

* Revert "rustfmt"

This reverts commit c380ab9185.

* Revert "(1)add verify_slate_messages for wallet receive (2)log the message content"

This reverts commit 9584ca7a89.

* [re-floonet] Keychain Floonet BIP32 version/network option (#2235)

* add 'is_floonet' property to keychain
* fix hex encoding and tests

* Fix couple floonet loose ends (#2230)

* Fix couple floonet loose ends. Fixes #2216
* Doc fix for sig message

* Refuse unkown kernel features (#2244)

* Minor: magic number change for re-floonet

* Set pre genesis is_secondary to true (#2247)

* Minor: tx validation error display underlying

* New floonet genesis

* genesis rustfmt

* Use chain-specific config for wallet toml gen

* Fix default wallet_listener_url

* New more reasonable genesis block, bumped version

* genesis rustfmt

* Couple minor fixes to genesis generation script
2018-12-28 14:46:21 -08:00
Gary Yu
c0507b2ab1 Ban a fraud peer which claims a fake height and total difficulty (#2237)
* ban a peer with highest height but can't send us the proper headers
* reset self.stalling_ts if syncing goes well
* fix: switch to peers.ban_peer() instead of peer.set_banned()
2018-12-28 14:09:09 -08:00
Gary Yu
55334caec8 fix: peers::is_banned need check peers data from database (#2243) 2018-12-28 13:54:37 -08:00
Ignotus Peverell
7284cfec72
Changed magic number and seeds for Floonet (#2188)
* Changed magic number and seeds for Floonet.
* Genesis generator now loads a local wallet seed to build coinbase.
2018-12-20 11:08:01 -08:00
Antioch Peverell
2d4538c428
Clean shutdown via stop_state (#2117)
* clean shutdown wip

* rustfmt

* introduce StopState that we can lock on

* rustfmt

* take lock on stop_state during critical processing (process_block_single etc.)

* rustfmt

* take lock on stop_state during chain::init()

* cleanup

* cleanup

* rustfmt

* docs/comments

* fixup servers tests

* cleanup p2p tests
2018-12-11 11:07:41 +00:00
hashmap
aedac483f5
Convert to Rust 2018 edition (#2084)
* Convert to Rust 2018 edition

* Update gitignore
2018-12-08 00:59:40 +01:00
hashmap
a6bb6344ac
Fix seed thread crash (#2096)
We get overflow in some tests, peraps in real life too
Fixes #2095
2018-12-07 17:09:26 +01:00
Ignotus Peverell
87bfd9aaa4
Mark all crates as publishable 2018-12-07 00:08:15 +00:00
Antioch Peverell
a3523028dc
Sync headers slice (#2085)
* pass slices of headers around, not vec of headers

* rustfmt
2018-12-05 16:50:32 +00:00
Antioch Peverell
7b07fe99a7
bump 0.4.1 -> 0.4.2 so we can watch the HF (#2057) 2018-11-30 11:20:12 +00:00
antiochp
f7608f5b9c
rustfmt 2018-11-16 14:34:05 +00:00
antiochp
4b48eebdfe
refactor some p2p to use Read/Write over TcpStream 2018-11-16 14:33:35 +00:00
Antioch Peverell
f0fa410273
Streaming headers (#1989)
* headers msg is now "streamed" off the tcp stream

* rustfmt

* cleanup

* move StreamingReader into ser.rs
extract read_exact out into util crate

* rustfmt
2018-11-16 11:00:39 +00:00
Antioch Peverell
cb652e7ef1
do not treat txhashset.zip download as abusive behavior (#1973)
* do not treat txhashset.zip download as abusive behavior

* count times, not bytes so we exclude quiet increments

* use inc_quiet when tracking sent bytes via an attachment

* add comment

* fixup "quiet" counter entries

* rustfmt
2018-11-13 21:34:45 +00:00
Antioch Peverell
01900f2e4d Enable TX_KERNEL_HASH capability by default (#1971) 2018-11-13 09:28:36 -08:00
Antioch Peverell
236fe56f60
ask for peers with PEER_LIST capability when asking for more peers (#1969)
do not simply look for peers with the same capabilities we have
2018-11-13 10:59:33 +00:00
Antioch Peverell
c631b45ab6
cleanup how we deal with flexible rproof size in ser/deser (#1965) 2018-11-13 09:30:40 +00:00
Antioch Peverell
a3c1c6d603
Do not use mem::size_of() when calculating serialized size of data (#1967)
* use FixedLength to define serialized size in bytes of various structs
replace usages of mem::size_of() with ::LEN so we correctly calculate serialized sizes in bytes

* rustfmt
2018-11-13 09:30:02 +00:00
Gary Yu
7ff1ee5fde
Peer send receive bytes statistics missed response messages and attachment (#1953)
* fix: peer send receive bytes statistics missed response message and attachment

* rustfmt
2018-11-11 07:30:57 +08:00
Gary Yu
2352275dff
Suppress some peers logs by trace level instead of debug (#1952)
* suppress some peers boring logs by trace instead of debug

* rustfmt
2018-11-11 07:30:14 +08:00
Gary Yu
9af9ca9518
refactor the state_sync to handle the long fork (#1902)
* split horizon into two explicit values for cut through and txhashset request

* let node which has 2-7 days of history be able to handle forks larger than 2 days

* add test simulate_long_fork

* add pause/resume feature on p2p for tests

* refactor the state_sync

* ignore the test case simulate_long_fork for normal Travis-CI

* refactor function check_txhashset_needed to be shared with body_sync

* fix: state TxHashsetDone should allow header sync
2018-11-10 11:27:52 +08:00
Antioch Peverell
39ebb33ba1
bump 0.4.0 -> 0.4.1 (tx kernel broadcast support) (#1950) 2018-11-09 14:57:25 +00:00
Ignotus Peverell
f7d0fe1840
Bug fix, tuning of peer message rate counting 2018-11-07 22:15:12 +00:00
Antioch Peverell
ab30f714fc
Capabilities now deserialize safely (#1946)
* deserialize capabilities dropping unknown flag bits

* add tests for capabilities deserialization

* rustfmt

* FULL_NODE needs to be handled safely for legacy nodes
2018-11-07 11:15:37 +00:00
Antioch Peverell
e25a3b9d72
Fix capabilities (#1944)
* we cannot safely update nodes to use capabilities bits = 15 ...

* rustfmt
2018-11-07 10:00:42 +00:00
Antioch Peverell
949f75c77c
fix the lock on the new mutex (#1942) 2018-11-07 09:40:39 +00:00
Antioch Peverell
d97a6c2189
[DNM] broadcast tx kernel hash (if supported by peer) (#1929)
broadcast tx kernel hash (if supported by peer)
2018-11-07 09:28:17 +00:00
Ignotus Peverell
8b546632fe
Peer rate limiting (#1933)
* Rate counter in peer conn to monitor traffic 
* Ban peers that trigger is_abusive
2018-11-06 17:51:22 -08:00
hashmap
d2088ff48c Fix recently introduced peer deadlock (#1941) 2018-11-06 16:42:36 -08:00
hashmap
8742c334dd Remove unsafe sync/send impl for Peers (#1938)
This is really unsafe. Fixes #1937

* Switch to better mutex
2018-11-06 08:59:46 -08:00
hashmap
0af1f13bf9 Fix IPV6 address deserialization (#1932)
Fuzz test found that we don't read IPV6 addr (as part of p2p message)
properly. The code is supposed to read 8 dwords, but [0..8] is not a
slice of 8 ints, but a slice of one Range, so we always read just one
dword
2018-11-05 20:38:41 -08:00
hashmap
109a426990
Add fuzz tests for p2p crate (#1931)
Add fuzz tests for p2p crate
2018-11-05 21:50:16 +01:00
hashmap
b01fcd2f56 Remove unused unsafe declarations (#1901) 2018-10-31 13:19:28 -07:00
Ignotus Peverell
46051ee174
improve minimum difficulty handling (#1791)
* rename MIN_DIFFICULTY to UNIT_DIFFICULTY; define Difficulty::unit, fix INITIAL_DIFFICULTY
* improve minimum difficulty handling
* replace all Difficulty::one by ::min
* revert secondary scaling default in HeaderInfo; rename scaling_difficulty; refactor difficulty_data_to_vector
2018-10-27 10:37:44 -07:00
Ignotus Peverell
c083312ad4
Improve crate descriptors to be more cargo-friendly (#1844)
* Update secp dependency to use crates.io version
* Add more details to various Cargo.toml
* Remove use of env variables that aren't reliably provided by cargo
2018-10-25 17:44:50 -07:00
Ignotus Peverell
a42d66efff
Merge branch 'master' into unitdiff 2018-10-25 14:20:41 -07:00
eupn
711fad6c24 Remove TODO for counting of bytes that was already done (#1838) 2018-10-25 15:57:53 +02:00
Antioch Peverell
38cbd6eafb
full node == fast sync (no full archival guarantees) (#1809)
* wip - fast sync only

* wip

* cleanup

* cleanup

* cleanup comments in default config file around capabilities

* fixup p2p tests
2018-10-23 13:01:19 +01:00
Ignotus Peverell
7f60e2076d
Default last connected to migrate older db (#1812)
Fixes backward compatibility issue with #1794
2018-10-22 18:15:10 -07:00
eupn
8f42f7306c feat: remove expired peers from the storage (#1794)
* Initial expired peers removal
* Stop expired peers
* Simplify peer removal and remove only Defunct peers
* Make seed to check for expired peers every hour
* Get rid of unused vector of peers to remove
* Make peer deletion predicate closure immutable
2018-10-22 13:59:40 -07:00
eupn
1195071f5b Replace logging backend to log4rs and add log rotation (#1789)
* Replace logging backend to flexi-logger and add log rotation
* Changed flexi_logger to log4rs
* Disable logging level filtering in Root logger
* Support different logging levels for file and stdout
* Don't log messages from modules other than Grin-related
* Fix formatting
* Place backed up compressed log copies into log file directory
* Increase default log file size to 16 MiB
* Add comment to config file on log_max_size option
2018-10-21 13:30:56 -07:00
Gary Yu
0d06561a91
replace stdlib RwLock and Mutex with parking_lot (#1793)
* replace all stdlib RwLock with parking_lot RwLock

* replace stdlib Mutex with parking_lot Mutex

* rustfmt
2018-10-20 08:13:07 +08:00
John Tromp
846b38308c replace all Difficulty::one by ::min 2018-10-18 21:18:16 +02:00
yeastplume
f94ede9af3 merge T4 into master 2018-10-18 11:23:04 +01:00
Gary Yu
53b10a083c
kick stuck peer out of connected peers. (#1782)
* cherry-picking commit 7754adb8 from master for #1746
2018-10-18 10:04:05 +08:00
Ignotus Peverell
b5cb227322
Last genesis for T4, unless I messed up something 2018-10-17 19:36:12 +00:00
eupn
b22fb55245 feat: add peers used bandwidth calculation and display in TUI (#1770)
* Add peers used bandwidth calculation and display in TUI
* Fix formatting
* Change Mutex to RwLock from peer's used bandwidth statistics in Tracker
* Make used bandwidth column in TUI peers list sort by sum of bytes
2018-10-17 10:01:42 -07:00
Yeastplume
b43d6e4326
[T4] Set genesis block data + initial secondary scaling correctly (#1776)
* ensure genesis block+pre genesis is populated correctly with secondary scaling

* rustfmt
2018-10-17 16:53:31 +01:00
Yeastplume
5cec885ef5
[T4] diff change (#1769)
* pre-t4 again

* rustfmt
2018-10-17 13:48:18 +01:00
Yeastplume
404165a8fd
[T4] Add sec pow info to TUI, change magic number, genesis diff to 1 (temporarily) (#1768)
* add sec scaling stats to tui

* rustfmt
2018-10-17 10:37:28 +01:00
hashmap
85433c659d Introduce a constant for peer send channel capacity (#1761)
We implicitly use it also in body_sync, so it's hard to keep it in sync.
2018-10-16 16:31:00 -07:00
Gary Yu
7754adb834 kick stuck peer out of connected peers (#1746)
* kick stuck peer out of connected peers
* adjust kick time to 2 hours
* stuck detection take into account own difficulty compare
2018-10-16 09:14:16 -07:00
yeastplume
4bb31dbdb4 update new genesis block, change p2p msg magic number 2018-10-16 10:16:54 +01:00
John Tromp
34646ddf51 [T4] Rename all shiftsize / cuckoo_size to edge_bits and change value for T4 (#1752)
* replace all size_shift / cuckoo_size by edge_bits and change some constants for T4
* replace remaining occurrences of sizeshift
2018-10-15 16:14:23 -07:00
yeastplume
9423865f92 update cargo versioning 2018-10-15 10:34:33 +00:00
Gary Yu
2e6a242827
small improvement on the servers test (#1737)
* cherry-pick from master for #1736
2018-10-14 20:13:49 +08:00
Gary Yu
6f4eb8dd2e
small improvement on the servers test (#1736)
* small improve on the servers test, to avoid Travis-CI failure on "job exceeded the maximum log length"

* rustfmt
2018-10-14 17:01:34 +08:00
Ignotus Peverell
00be540e0c Fix small txhashset download timeouts (#1735) 2018-10-14 15:25:17 +08:00
Ignotus Peverell
43f4f92730
[T4] Secondary proof of work difficulty adjustments (#1709)
* First pass at secondary proof of work difficulty adjustments
* Core and chain test fixes
* Next difficulty calc now needs a height. Scaling calculation fixes. Setting scaling on mined block.
* Change factor to u32 instead of u64.
* Cleanup structs used by next_difficulty
* Fix header size calc with u32 scaling
2018-10-13 13:57:01 -07:00
Gary Yu
9a716aea72
feature: txhashset downloading progress display on tui (#1729) (#1730)
(cherry picked from commit 5c0eb11a7d)
2018-10-13 10:12:13 +08:00
Gary Yu
5c0eb11a7d feature: txhashset downloading progress display on tui (#1729) 2018-10-12 15:53:50 -07:00
Gary Yu
3fb4669d0a
small speed optimization for header sync (#1728)
* fix: avoid a confusing log when fastsync start (#1720)

(cherry picked from commit 4f462cdfdc)

* small speed optimization for header sync (#1719)

(cherry picked from commit d3589d1bf5)
2018-10-12 08:44:35 +08:00
Gary Yu
d3589d1bf5
small speed optimization for header sync (#1719) 2018-10-11 16:47:27 +08:00
Antioch Peverell
8cfe9e64ac
Remove RwLock around individual peer instances (#1673)
* get rid of RwLock around peer instances

* rustfmt

* rename stuff to live_info

* rustfmt

* serialize into PeerInfoDisplay
limit live_info write lock to peer_info.update()
rename to PeerLiveInfo

* simplify broadcast logic a bit more
connected peers are connected by definition

* return true/false on broadcast so we can send to more peers

* rustfmt

* fix p2p and server tests for PeerInfoDisplay

* commit
2018-10-09 08:27:34 +01:00
Antioch Peverell
de5b6868fb
Add last_seen to peer info (#1688)
* add last_seen to peer and update on ping/pong
expose last_seen in tui

* rustfmt

* chrono serde features
2018-10-08 13:39:52 +01:00
Gary Yu
1a6101f870 refactor: remove thread p2p-moniter, move the Ping to the connect_and_monitor (#1670) 2018-10-07 10:24:06 -07:00
Gary Yu
463567b19e
optimization of peer state write lock (#1669)
* optimization of peer state write lock
2018-10-07 13:01:32 +08:00
Gary Yu
a37f7bbcab
improvement on peer lock for ping/pong (#1668)
* peer lock optimization for ping/pong
* is_banned peer lock use read lock instead of write
2018-10-07 08:00:53 +08:00
Antioch Peverell
c86578c2a9 Peers broadcast fixes (#1667)
* peers broadcast fixes
* stop at num_peers...
2018-10-05 16:53:55 -07:00
Gary Yu
697805752c fix: seed thread panicked on a try_read unwrap 2018-10-05 21:16:44 +08:00
Ignotus Peverell
85d5feafa3 Fix concurrency issue around peer add and start. Fixes #1585 (#1633)
* Fix concurrency issue around peer add and start. Fixes #1585
2018-10-02 10:17:29 -04:00
Antioch Peverell
c9c829514b
Trace get block (#1628)
* trace on GetBlock msg

* rustfmt
2018-10-01 22:12:39 +01:00
Gary Yu
8d62247c99 Small cleanup of rand usage (#1576)
Clean 3 build warning of deprecated item 'rand::Rand::rand'
2018-09-24 15:15:55 -07:00
Gary Yu
56ffbee7e9
fix: all fast sync nodes report to peers as full nodes (#1547)
* fix: all fast sync nodes report to peers as full nodes
2018-09-20 07:09:39 +08:00
Ignotus Peverell
9cc7aed713
Dual proof of work, first step (#1534)
* Move Proof and Difficulty types to pow module. Difficulty scaling calculation.
* Diffculty scaling and size shift for 2nd PoW
* Backport e7eb26ee
* Test compilation fixes
* Scaling only need to go one way, as @tromp pointed out
2018-09-18 15:12:57 -07:00
Antioch Peverell
c291c48436 Simplify block broadcast (#1549)
* removed random "block vs compact_block"
2018-09-18 10:51:37 -07:00
Antioch Peverell
a4476443bb
Compact transactions (initial prep work) (#1548)
* introduce CompactTransaction (unused currently)

* rustfmt

* fix comments
2018-09-18 15:25:26 +01:00
Quentin Le Sceller
345a6cb53e Update rand crate to 0.5 (#1542)
* Update rand crate to 0.5

* Rustfmt

* Misplaced import
2018-09-18 09:39:45 +01:00
Gary Yu
a0deb18e77
Update version of some crates (#1536)
Update version of some crates
2018-09-17 10:47:48 +08:00
Gary Yu
4a5a91a9cf Fix: clean_peers is using connected_peers, which make it do nothing (#1505)
* a failed handshake for example don't deserve banning
* remove not used 'BadOthers' from ReasonForBan
2018-09-13 09:53:35 -07:00
Gary Yu
7a689d468c Remove 'WebStatic' seed_type since it was obsoleted a while ago (#1512) 2018-09-11 20:28:27 -07:00
Gary Yu
0dbfed5971 return an Err when read return 0 (#1503)
* return an Err when read return 0, instead of all zeroed buff without any error
2018-09-11 13:14:48 +02: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
hashmap
da87f5fef4 Don't wait 30 seconds in case of a quick restart (#1488)
Currently on startup we wait for 30 secs if we don't have at least 4 peers with more work. If a node was quickly restarted it is already fully synced so thereare no peers with more work at all. This pr assumes that if we've done some work already and we have enough peers but still 0 with more work we are fully synced and good to go.
2018-09-07 13:01:54 -07:00
Gary Yu
ed73db671f fix for unstable travis-ci test on servers module (#1434)
* fix for unstable travis-ci test on servers module

* skip the PeerWithSelf connection request on sending side

* logs and comments change; and remove an unnecessary unwrap() in test
2018-09-04 10:52:11 +02: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
8a39f1fc75 Use 10us sleep instead of 1ms sleep (#1453) 2018-08-31 13:20:59 -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
Yeastplume
1ded3f3972
Config + Default directories (#1433)
* config file can now be generated by executable

* rustfmt

* remove now-unnecessary config defaults test

* set up paths and config file creation in user's home directory

* rustfmt

* remove default grin.toml

* add grin configuration command to spit out config file

* Split configuration into wallet and server

* rustfmt

* Restore logging to wallet configurations

* rustfmt
2018-08-30 10:10:40 +01:00
Gary Yu
471e80e69e fix for peer connect fail on 'WouldBlock' Error (#1440)
* fix for fail of peer connect: 'WouldBlock' Error.

* reuse the blocking variation of read_exact instead of re-implementing the loop
2018-08-30 08:21:13 +01:00
hashmap
67d2a04e92 Fix non-atomic peer update 2018-08-28 13:26:47 +02:00
Quentin Le Sceller
8cd1b23f7a Add a peers_preferred option in Grin (#1401)
* Preferred peers option
* Move P2P configuration into proper config part
* Fix tests
2018-08-23 15:16:04 -04:00
hashmap
7dd2888b71 Get peers as quick as possible (#1398)
* Get peers as quick as possible. Currently we get 2 peers and then wait 20 seconds before trying to get more
* Second pass
* Fix peer_count
2018-08-22 21:31:06 -04: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
hashmap
631201358f Refactor and optimise peers.rs (#1389)
* Use internal hashmap for count and contains methods instead of relying on
connected_peers method which is expensive (creates vector from hashmap)
* Reduce number of `clone()`
* Refactor broadcast_xxx
2018-08-20 18:32:13 -04:00
Antioch Peverell
7ca4d45bf5
Cleanup build warnings (#1391)
* cleanup some unused vars etc.

* rustfmt
2018-08-20 21:56:32 +01:00
Antioch Peverell
5abefbff33
improve logging when receiving blocks and txs (msg_len) (#1383)
* better logging for msg_len and # kernels

* rustfmt
2018-08-19 18:15:42 +01:00
Ignotus Peverell
630d0a0438
Buffered txhashset temp file write 2018-08-18 02:52:44 +01:00
Ignotus Peverell
d47a3bc225
Simplify and improve headers_received (#1362) 2018-08-16 22:30:05 -04: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
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
Gary Yu
63a4d95df1 fix: in case txhashset validation fail, 'TxHashsetDownload' should retry (#1293) (#1322)
* fix: in case txhashset validation fail, 'TxHashsetDownload' should retry (#1293)

And add 2 more fixes:
1. handle sending request failure of 'send_txhashset_request';
2. use a 10-mins timeout to handle noresponse failure, in case a peer ignore our txhashset request, or in case a peer fail to send a file for some reason.
2018-08-08 17:14:54 +02:00
e-max
25e3d9e7d3 Remove Iron dependency and update hyper to version 0.12 (#1241)
* Remove Iron dependecy and update hyper to version 0.12 #876

* REMOVE ME

* Revert "REMOVE ME"

This reverts commit e9a976eee98a2d5a4dfae5d9e1e4f5ed640c05d3.

* Rebase and start updating libwallet

Libwallet doesn't compile yet.

* Wallet compiles

* Grin compiles

* No compilation errors in tests

* All tests pass

* Reeturn future from handler

* Refactoring

* Fix lifetime issue one more time

I have to force push to rollback all the work done in last 2 days

* Fix wallet send issue

* Clean up
2018-08-01 10:44:07 +01: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
Gary Yu
3b6b85ec57 Fix fast sync mode failure when 'sync_state' was switched to 'HeaderSync' (#1286) 2018-07-23 10:37:35 -07:00
Ignotus Peverell
a45d17257a
Cleanup ping-pong serialization 2018-07-13 00:55:21 +01:00
Ignotus Peverell
bdfd5405c0
Leverage sync state to accept txhashset (#1251)
Fixes #1246
2018-07-12 17:06:52 +01:00
Quentin Le Sceller
b5fe22dbd5 Bump to 0.3 (#1225) 2018-07-06 18:29:39 +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
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
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
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
Quentin Le Sceller
663733e72b
Replace try! for ? (#1134)
* Replace try for ?
2018-06-04 12:05:49 -04:00
Quentin Le Sceller
d6b689bada
Simplify DandelionConfig (#1115)
* Simplify DandelionConfig and make fields optional
2018-06-01 18:41:39 -04: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
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
Antioch Peverell
982dae99a5
make enum values explicit (#1101) 2018-05-29 17:57:11 -04: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
Casey Rodarmor
bc3b8b1664 Add spaces between methods in Peers ChainAdaptor (#1025)
Aside from being a bit easier to parse, it helps vim users
navigate using the `{` and `}` motions
2018-05-01 21:39:22 -04:00
Antioch Peverell
bc6342ea65 Fix issue where we have no metadata for a block (#938)
when restarting node before initial sync completed
2018-04-06 17:14:50 +00:00
Quentin Le Sceller
b9de134209 Full sync ask blocks only from other archival nodes (#930)
* Request body_sync only from archival node
* Move verification to p2p crate
* Additionnal check on capabilities
* Add check block 1
2018-04-06 03:06:34 +00:00
Simon B
98efaf88df mixed small stuff (#934)
* documentation and spelling
* unused values in tests; just .unwrap()
* unneeded macro_use (router)
* unneeded macro_use and use-imports
* unused value -> .unwrap
* unused variables
* clarify that " is required (see 107ea3c4dd)
* first steps to dig into #933 test_p2p issues
* less simulnet build warnings
2018-04-05 23:31:34 +00:00
Ignotus Peverell
85ee5041aa
Sync improvements (#923)
* Added additional message type size limits
* Externalize sync loop state, check if we received all
* Adjusted some message sizes, log error when too short
* 4x limits to give ourselves more space
* No need for sync to wait if we have enough peers.
* Tolerate a few less headers before considering we got them all.
2018-04-03 20:21:13 +00:00
Ignotus Peverell
5ba0dbf38d
Fix and cleanup of fast sync triggering logic (#916)
* Fix and cleanup of fast sync triggering logic
* New txhashset on fast sync has to be applied, not rolled back
* Do not block if peer send buffer is full, fixes #912
2018-03-30 06:02:40 +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
ea9a978c87
Tui update 1 (#911)
* minor low-hanging TUI updates

* rustfmt

* make diff/height output clearer
2018-03-29 12:29:17 +01:00
Ignotus Peverell
c3cec63a95
Use a sync channel for peer sending. Fixes #904 2018-03-29 00:00:34 +01:00
hashmap
083d4564c3 Log ping/pong only in case of a discrepancy (#893)
Not a fix for #888 but related
2018-03-27 21:33:13 +00:00
Ignotus Peverell
8693764488
Minor typo fix and mut cleanup 2018-03-27 19:06:54 +01:00
Yeastplume
28985bad55 Make peer parameters user-configurable (#883)
* make peer parameters user-configurable
* rename peer_preferred_count to peer_min_preferred_count
2018-03-27 17:17:01 +00:00
Antioch Peverell
4fcf5fdbca
drop msgs received from a banned peer (#886) 2018-03-27 12:09:41 -04:00
Antioch Peverell
90c71625aa shorter log msg for ping/pong (#882) 2018-03-27 14:23:19 +01:00
hashmap
e32d353543 Externalize Grin User Agent (#880)
Take the version from the root Cargo.toml
Fixes #875
2018-03-27 13:52:59 +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
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
Simon B
a8fc82d8c1 Console debug fixes (#861)
* move some debug! to trace!

* more informative debugs

* standardising on always showing chain tips as "cumulative difficulty @ height [hash]"

* make 2 debug outputs into a single

* "no peers" as warning (not info) to let it stand out more clearly

* move fn param (used only in this one debug line)

* clarify difficulty "units"
2018-03-25 12:41:12 -04: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
Quentin Le Sceller
836391cc53 Dandelion relay update (#825)
* Change error logger to debug logger
* Dandelion relay update after monitor peers
* Typo + kick off Travis build
2018-03-22 22:51:09 +00: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
Quentin Le Sceller
fcfe7bc6a4 Basic Dandelion transaction routing (#719)
* Initial Dandelion Commit
* Changed stem_tx_pool to tx_stempool
* Introduction of stem memory pool and stem pool config
* Pool push now send to stem memory pool
* Add stem transaction functions
* Add stem transaction pool
* Drastically simplified code structure
* Add monitor transactions
* Add Dandelion monitor and remove transactions from stempool
* Add peer relay monitor
* Reconcile block with stempool
* Fix total size bug
* Add fluff option for pool push
* Added details on dandelion monitor
* Fix issue with missing parent
* Child transaction with stempool parent are now forced stem
* Update Dandelion Relay from outgoing peers
* Fix missing pool reconciliation
* Add the ability to fluff a transaction directly
* Fix tests for Dandelion
* Missing send_stem_transaction method...
* Add fluff handler for wallet
* Add logger when successfully updated Dandelion relay
* Launch transaction monitor last
* Fix dandelion relay misplaced
* Add logging and updating for stempool
* Additionnal check for stem transaction
* Fix 2 Locks in a row
2018-03-20 03:18:54 +00:00
Yeastplume
e268993f5e
[WIP] Needs more TUI (#765)
* first explorations at attempting to integrate more user-friendly status screen/ui

* rustfmt

* adding some logo and color for visual interest

* formatting

* better integration with stdout, cleaner looking startup and shutdown

* rustfmt

* update to framework, and first collection of stats from server

* rustfmt

* commit of basic stat screen, think it's in a good enough state to share

* rustfmt

* fix to automated tests

* fix to automated tests

* grin.toml setting

* grin.toml setting

* grin.toml setting

* merge from upstream

* merge from upstream

* merging

* merging

* formatting

* adding more status screens, beginning to collect peer data

* rustfmt

* beginnings of peer info

* adding tui dir

* rustfmt

* missing table

* create title bar

* Split up UI elements into separate files, create trait for update

* Added basic mining view
2018-03-13 18:10:45 +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
Ignotus Peverell
be8d9633e4
rustfmt all the things 2018-03-04 00:19:54 +00:00
Alexey Miroshkin
d116a434bf Log the reason of peer ban (#736)
This PR fixed #455 by adding a few debug log messages
2018-02-27 20:33:40 +00:00
Quentin Le Sceller
ccf8eb9eeb Add Inbound/Outbound for connected peers (#725)
* Add Inbound/Outbound for connected peers

* Fix tests

* Undo removing trailing commas

* Revert "Fix tests"

This reverts commit 0d024188d4.
2018-02-24 16:00:38 -05:00
Quentin Le Sceller
755d0b7902 Typo broadcast/transaction (#718) 2018-02-20 21:27:18 +00:00
Antioch Peverell
4022b82817
cleanup various build warnings (#714)
* cleanup various build warnings

* use serde_json in tests only
2018-02-17 12:56:22 -05: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
Ignotus Peverell
76796738c1
Clean server shutdown, generalizes usage of Weak (#700)
* Clean server shutdown, generalizes usage of `Weak`. Introduces 2 main changes:

  * A shared `AtomicBool` that signals server shutdown. All server
threads regularly check it to break out of their main loops when
it changes to `true`.
  * Breaking of circular `Arc` references, which can never be
destroyed, by downgrading to `Weak` instead. Only the main server
keeps the `Arc` while all other components get the `Weak` variant.

Both of these are required for all long-living structs to be
cleanly destroyed. Note that in Rust this is fairly important as
most resource-freeing logic is associated with `drop`,
which is only called when said struct is free of scope or `Arc`
references.

Should address most of #536 (only need the stop hook to call
`Server` shutdown).

* Test for fast sync, followed by restart, followed by re-fast-sync

* P2P test fix

* Double sync taking too long for Travis, commenting out for now
2018-02-13 00:38:52 +00: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
78a6447a09
fix bad merge - missing support for header msg type (#690) 2018-02-07 11:26:52 -05:00
Ignotus Peverell
eb0ebab2d3
Add forgotten ping loop, fix TCP send interlacing 2018-02-05 23:09:57 +00:00
Ignotus Peverell
a9f4f36117
P2p ping and partial header reads fixes (#684)
* Re-introduce peer regular ping/pong
* Fix partial header reads. Turns out that on async tcp streams, even a small chunk like a
header can be read partially. So header read needs to rely on our
fixed-up `read_exact`, with an additional boolean to allow yield
when no bytes were read.
2018-02-05 19:52:11 +00:00
Quentin Le Sceller
fb46fad0ac Remove unused import and uniformize crates (#686)
* Removed unused crates
* Add listconnectedpeers in grin client
* Removed unused import and uniformize crates
2018-02-05 19:46:56 +00:00
Ignotus Peverell
c7418cfe04
[WIP] Rewrite peer-to-peer logic to replace tokio with simple threading (#664) 2018-02-02 02:03:12 +00: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
3f15f7f2f9
Request compact blocks (#667)
* first pass at allow/deny lists for hard-coded peers (not just seeds)

* commit

* add peers_allow and peers_deny examples and comments to grin.toml

* always ask for compact block
always fail to hydrate
always fallback to requesting full block

* decide to send full (empty) block over compact (empty) block

* add some randomness to the decision around broadcasting an empty block
as a block or as a compact block (so we can exercise more code paths easily)
2018-01-31 15:39:55 -05:00
Antioch Peverell
5fd47fb875
peers_allow/peers_deny in grin.toml (#665)
* first pass at allow/deny lists for hard-coded peers (not just seeds)

* commit

* add peers_allow and peers_deny examples and comments to grin.toml

* fix build issue with simulnet tests

* fix p2p tests
2018-01-30 16:44:13 -05:00