Commit Graph

1256 Commits

Author SHA1 Message Date
onryo
58b65f9670 Update copyrights 2024-02-27 23:59:59 +01:00
Duke
07b041fd94 Do not apply overwinter/sapling consensus rules to block 0 2024-02-15 10:40:22 -05:00
Duke
bc0af82ce6 SMART_CHAIN_SYMBOL is always defined, no need to check which slows this hot path down 2024-01-24 11:25:48 -05:00
Duke
27db254d68 Sapling and Overwinter network upgrades are always active
These NU's are always active for Hush Arrakis Chains so this code only serves
to slow down all operations by constantly being checked. So we disable them
which will speed up syncing, mining and creating transactions.
2024-01-21 16:34:53 -05:00
Duke
b0b9565d6a Sapling and Overwinter network upgrades are always active 2024-01-21 15:32:23 -05:00
Duke
3a3c67e0fc Delete many things we do not want or need 2024-01-13 00:06:09 -05:00
Duke
7d73ebd7af Remove voutsum variable which is calculated but never used 2024-01-07 10:25:36 -08:00
Duke
196e00c786 Remove unused variables 2024-01-07 10:24:12 -08:00
Duke
c1ab82a881 Remove unused variables and add a const 2024-01-06 23:57:39 -08:00
Duke
4054140b21 RandomX interval and block lag are consensus changes and will never change at run-time, so they can be static 2024-01-06 23:47:00 -08:00
Duke
447f1f50f3 SMART_CHAIN_SYMBOL is always nonzero 2024-01-06 23:39:24 -08:00
Duke
b9937bc5d2 Release randomx cache in normal exit 2024-01-06 23:37:48 -08:00
Duke
1b5422eb2d Dynamically determine thread count for dataset init 2024-01-07 02:19:03 -05:00
Duke
56ef56b136 randomx_get_flags() automatically sets all flags except RANDOMX_FLAG_FULL_MEM, RANDOMX_FLAG_LARGE_PAGES and RANDOMX_FLAG_SECURE 2024-01-06 22:30:41 -08:00
Duke Leto
0e0b1cca97 Attempt to try different randomx flags 2024-01-06 21:33:23 -08:00
Duke
943ffbc1bf Remove unused variables in BitcoinMiner/RandomXMiner which saves about 3.5KB of memory per mining thread 2023-12-27 08:37:20 -05:00
Duke
43aa4a7d90 Create a local variable instead of modifying the global ASSETCHAINS_SCRIPTPUB 2023-12-25 14:05:05 -05:00
Duke
5cf38dd5db Merge branch 'dev' into danger 2023-10-13 09:27:38 -04:00
Duke
80bd3f262c Verbosify randomx debug logging in case that helps debug mismatched height coinbase issue 2023-10-12 10:01:01 -04:00
Duke
fc6745129d Fix randomx memory leak but create some mining errors
This change lifts the declaration of the randomx VM out of an inner loop
into the main function body of RandomXMiner(), which allows us to destroy
it later on when catching exceptions. We cannot lift the allocation of it's
memory (randomx_create_vm) because it depends on things that change in every
iteration of the inner loop. Otherwise, the VM will only sometimes
be destroyed, which is what I think causes the memleak.

But this seems to create one invalid block when mining each block height :

STDOUT:

TestBlockValidity: failure C checkPOW=1
RandomXMiner: Invalid randomx block mined, try again 05f30f419133b2d862106b89c20059967639e4f2699dd5afc5d2b0832f1ac76a

debug.log:
2023-10-11 16:10:41 CreateNewBlock(): total size 1000 blocktime.1697040642 nBits.200e77d1
2023-10-11 16:10:41 Running HushRandomXMiner with 1 transactions in block (260 bytes)
2023-10-11 16:10:41 ERROR: ContextualCheckBlock: block height mismatch in coinbase

Mining does seem to continue normally when testing with -testnode=1
2023-10-11 12:07:40 -04:00
Duke
963ce1e444 Release randomx dataset+cache when mining is interrupted or errors 2023-10-10 22:04:15 -04:00
Duke
7db6745056 s/zouts/zins/ in debug log 2023-10-10 12:05:53 -04:00
duke
38699a7d47 Merge pull request 'Antispam defenses' (#322) from antispam into dev
Reviewed-on: https://git.hush.is/hush/hush3/pulls/322
2023-10-10 15:55:11 +00:00
Duke
c8a88e1168 Check null randomx dataset before calling randomx_dataset_item_count 2023-10-07 14:07:34 -04:00
Duke
2308db22ee Antispam defenses
This code is inspired by
db292a49dd
with various improvements that will be documented below.

The largest improvement is that this code will defend against a spammer using shielded inputs (zins)
or shielded outputs (zouts) while the Pirate code only defends against zout spam.

We wrote a new RPC called z_getstats to study exactly what the distribution of shielded inputs (zins)
and shielded outputs (zouts) look like on HUSH mainnet. Sietch will never make a ztx that contains
more than 9 zouts and so transactions with 10 or more zouts are extremely rare. They correspond to custom
transactions created via code or CLI or mining pool payouts. We allow at most one of these per block. If
there are two, one will remain in the mempool and be mined in the subsequent block. Our code is more strict,
as Pirate will allow up to 6 of these transactions in a single block.

Transactions with many shielded inputs do occur normally when users spend many small shielded unspent outputs
(zutxos) in one transaction, but we determined that a cutoff of 50 zins is quite rare. Between blocks
14000000 and 15000000 only 27 ztxs had 50 or more zins, which is 0.03% . We allow at most one of these
per block and if there are more, they will wait to be mined in a subsequent block.

Also note that a transaction can match both criteria of having large zins and large zouts, so for instance,
if there is a transaction with 50 zins and 10 zouts, it counts towards both requirements and no other
transactions with >=50 zins or >=10 zouts will be mined in that block.

If >=200 transactions with either large zins or large zouts are broadcast to the network it will take at least
200 blocks for them to be mined and so via existing rules for ztx expiration they will expire and be removed
from the mempool, since by default all ztxs expire after 200 blocks. Since normal ztxs that match these
criteria are very rare, the only case when this might happen is during a spam attack and so the attackers
transactions expiring is another part of these defenses.

Other improvements are that we log txids of transactions with large zins or zouts and we do not support a
command line option to turn this protection off. This forces a potential attacker to compile their own custom
code if they want to subvert these protections on their own node and blocks they mine.

Similar to Pirate, these changes are not consensus changes but may be made consensus requirements
in the future.

These protections are not specific to HUSH and are enabled for all HSC's, including DragonX.
2023-09-18 13:30:40 -04:00
Duke
479ed54ff0 Add devtax address and scriptpub to getblocktemplate output 2023-06-23 09:13:11 -04:00
Duke
9f92bdd7dc Decentralized Devtax 2023-06-19 09:32:32 -04:00
Duke
fc921eba57 Remove dead code 2023-06-09 00:00:42 -04:00
Duke
bde7273c9f Remove mapRequest tracking 2023-03-14 15:54:28 -04:00
Duke
e033a2e6eb Update copyrights to 2023 2023-02-09 18:06:03 -05:00
Duke Leto
b7adb511a6 cleanup 2022-11-15 19:13:31 -05:00
Duke Leto
665f895134 Optimize inner mining loop 2022-11-15 14:40:10 -05:00
Duke Leto
c8b2163c1c Optimize inner mining loop 2022-11-15 14:21:45 -05:00
Duke Leto
1a4e8d4acf Initialize randomx dataset with 2 threads 2022-11-15 14:11:55 -05:00
Duke Leto
c55d1cbc5f Destroy randomx VM when we are done with it 2022-11-15 14:02:02 -05:00
Duke Leto
d3b948005c indentation 2022-11-15 13:44:47 -05:00
Duke Leto
3dbe8d3c6b indentation 2022-11-15 13:43:10 -05:00
Duke Leto
c108db8f3c Speed up randomx hashing by ~60X per core
These code changes move various randomx setup code out of the inner mining loop,
which significantly increases hashrate. Currently seeing ~60 hashes/second/core
on a Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz.

This code may have memory leaks, it does not destroy the randomx VM since it was
causing coredumps. It also seems to use more memory, I am only able to mine on 2
cores with 16GB of RAM. Using more cores runs out of memory.
2022-11-11 06:42:51 -05:00
Duke Leto
b94ec80307 Use RANDOMX_FLAG_FULL_MEM 2022-11-10 22:38:04 -05:00
Duke Leto
5aea752337 Fix compiler warnings 2022-11-08 09:16:27 -05:00
Duke Leto
6eccab3e98 Add missing newline in rxdebug and add debugging about solutionTargetChecks 2022-11-08 09:07:49 -05:00
Duke Leto
8e1ba0658d Ensure pindexPrev is not null before mining against it in both BitcoinMiner and RandomXMiner 2022-09-18 10:27:48 -04:00
jahway603
b2987b43f0 miner: fix MAXSOLS 2022-09-07 01:10:53 -04:00
Duke Leto
a70897966a Only print out randomx debug stuff when -debug=randomx 2022-07-11 18:33:10 -04:00
Duke Leto
66e9bd835a less debug 2022-07-08 09:42:54 -04:00
Duke Leto
8ca330dc68 cleanup 2022-07-04 01:45:05 -04:00
Duke Leto
7dfa3f9475 cleanup 2022-07-04 01:08:45 -04:00
Duke Leto
22f353cb61 Use the current block template as randomxInput 2022-07-03 13:20:13 -04:00
Duke Leto
d078eed3cf reduce some debugging in non-randomx code 2022-07-02 11:04:28 -04:00
Duke Leto
5a742dfc9d Make our initial randomx key longer, at least 9 bytes of entropy 2022-07-02 10:57:01 -04:00