66 Commits

Author SHA1 Message Date
Ori Newman
a4bb070722
[NOD-754] Fix staticcheck errors (#627)
* [NOD-754] Fix staticcheck errors

* [NOD-754] Remove some unused exported functions

* [NOD-754] Fix staticcheck errors

* [NOD-754] Don't panic if out/in close fails

* [NOD-754] Wrap outside errors with custom message
2020-02-18 16:56:38 +02:00
stasatdaglabs
f46dec449d [NOD-510] Change all references to Bitcoin to Kaspa (#531)
* [NOD-510] Change coinbase flags to kaspad.

* [NOD-510] Removed superfluous spaces after periods in comments.

* [NOD-510] Rename btcd -> kaspad in the root folder.

* [NOD-510] Rename BtcEncode -> KaspaEncode and BtcDecode -> KaspaDecode.

* [NOD-510] Rename BtcEncode -> KaspaEncode and BtcDecode -> KaspaDecode.

* [NOD-510] Continue renaming btcd -> kaspad.

* [NOD-510] Rename btcjson -> kaspajson.

* [NOD-510] Rename file names inside kaspajson.

* [NOD-510] Rename kaspajson -> jsonrpc.

* [NOD-510] Finish renaming in addrmgr.

* [NOD-510] Rename package btcec to ecc.

* [NOD-510] Finish renaming stuff in blockdag.

* [NOD-510] Rename stuff in cmd.

* [NOD-510] Rename stuff in config.

* [NOD-510] Rename stuff in connmgr.

* [NOD-510] Rename stuff in dagconfig.

* [NOD-510] Rename stuff in database.

* [NOD-510] Rename stuff in docker.

* [NOD-510] Rename stuff in integration.

* [NOD-510] Rename jsonrpc to rpcmodel.

* [NOD-510] Rename stuff in limits.

* [NOD-510] Rename stuff in logger.

* [NOD-510] Rename stuff in mempool.

* [NOD-510] Rename stuff in mining.

* [NOD-510] Rename stuff in netsync.

* [NOD-510] Rename stuff in peer.

* [NOD-510] Rename stuff in release.

* [NOD-510] Rename stuff in rpcclient.

* [NOD-510] Rename stuff in server.

* [NOD-510] Rename stuff in signal.

* [NOD-510] Rename stuff in txscript.

* [NOD-510] Rename stuff in util.

* [NOD-510] Rename stuff in wire.

* [NOD-510] Fix failing tests.

* [NOD-510] Fix merge errors.

* [NOD-510] Fix go vet errors.

* [NOD-510] Remove merged file that's no longer relevant.

* [NOD-510] Add a comment above Op0.

* [NOD-510] Fix some comments referencing Bitcoin Core.

* [NOD-510] Fix some more comments referencing Bitcoin Core.

* [NOD-510] Fix bitcoin -> kaspa.

* [NOD-510] Fix more bitcoin -> kaspa.

* [NOD-510] Fix comments, remove DisconnectBlock in addrindex.

* [NOD-510] Rename KSPD to KASD.

* [NOD-510] Fix comments and user agent.
2019-12-12 15:21:41 +02:00
Svarog
369ec449a8 [NOD-509] Change organization name to kaspanet (#524)
* [NOD-509] Change organization name to kaspanet

* [NOD-509] Reorganize imports
2019-12-08 17:33:42 +02:00
Svarog
f4c6859e51 [NOD-509] Updated repository and imports to github.com/daglabs/kaspad (#521) 2019-12-08 16:28:53 +02:00
Ori Newman
a789680db1 [NOD-314] change pkscript to scriptpubkey (#400)
* [NOD-314] Change everywhere PkScript to ScriptPubKey

* [NOD-314] Change everywhere PkScript to ScriptPubKey

* [NOD-314] Rename pkPops -> scriptPubKeyPops
2019-09-15 11:09:36 +03:00
stasatdaglabs
bfdf7a2cf2 [NOD-237] Implement transaction mass (#355)
* [NOD-237] Implemented transaction mass.

* [NOD-237] Added transaction mass validation to the mempool.

* [NOD-237] Made blockMaxMassMax not rely on MaxBlockPayload.

* [NOD-237] Added comments describing the new constants in validate.go.

* [NOD-237] Changed the default blockmaxmass to 10,000,000.

* [NOD-237] Fixed a comment that erroneously didn't refer to mass.

* [NOD-237] Added comments to ValidateTxMass and CalcTxMass.

* [NOD-237] Renamed "size" to "byte". Made validateBlockMass exit early if validation fails. Fixed unit names in comments. In CalcTxMass, moved summing of mass to the bottom of the function.

* [NOD-237] Instead of ErrMassTooHigh, renamed ErrBlockTooBig and ErrTxTooBig. Replaced wire.MaxBlockPayload with MaxMassPerBlock.

* [NOD-237] Fixed sanity checks related to block size in commands.

* [NOD-237] To use up less memory during testing, made the mass in the "too big" test come from pkScripts rather than input bytes.

* [NOD-237] Added an overflow check to validateBlockMass.
2019-08-05 16:04:24 +03:00
Ori Newman
263737b3fb [NOD-196] move coinbase scriptpukey to payload (#330)
* [NOD-196] move coinbase scriptpukey to payload (no tests) (#311)

* [NOD-196] Move coinbase scriptPubKey to payload

* [NOD-196] Rename SubnetworkID.IsFull to SubnetworkID.IsBuiltIn

* [NOD-196] Fix comments

* [NOD-196] Add block subsidy to fee transaction

* [NOD-196] Fix comments

* [NOD-217] Merge coinbase and fee transaction (#328)

* [NOD-196] Fix tests

* [NOD-196] Fix tests

* [NOD-217] Add error to getBluesFeeData

* [NOD-217] Merge Coinbase and fee transaction

* [NOD-217] Format project

* [NOD-217] Remove OpTrue default for mining.NewBlockTemplate

* [NOD-196] Format project

* [NOD-217] Add missing space before comment

* [NOD-196] Change MaxCoinbasePayloadLen to 150
2019-06-17 17:43:13 +03:00
Svarog
396842ae40 [NOD-207] Rename any place that says 'OutPoint' to 'Outpoint' (#323)
* [NOD-207] Rename any place that says 'OutPoint' to 'Outpoint'

* [NOD-207] Fix any place that says output point
2019-06-05 16:23:57 +03:00
Svarog
072c753323 [NOD-216] Revert implicit fee transaction (#322)
* Revert "[NOD-214] Remove Fee transaction from addrindex (#321)"

This reverts commit e4b2d869d49471021c56cb27cbc3001134b94dfd.

* Revert "[NOD-195] Make fee tx implicit (#315)"

This reverts commit ccca580a4b3ff8a44138041c0ce3bc0ce5847a4d.
2019-06-05 12:54:51 +03:00
Svarog
ccca580a4b [NOD-195] Make fee tx implicit (#315)
* [NOD-195] Made fee tx implicit

* [NOD-195] Removed redundant checks for fee transactions

* [NOD-195] Add fee tx data into acceptence data and fee data

* [NOD-195] Fix some tests

* [NOD-195] Update Block100000 with new data

* [NOD-195] Fixed remaining tests

* [NOD-195] Save and load feeTx to/from database

* [NOD-195] Remove DisconnectBlock methods from indexers, since they are not used anywhere

* [NOD-195] Add fee tx to addrindex

* [NOD-195] Don't populate inputs for fee transactions

* [NOD-195] Delete feeTxBucket in removeDAGState

* [NOD-195] Got rid of util.FeeTRansactionIndex
2019-06-03 17:30:57 +03:00
Svarog
ca0619bbcf [NOD-176] Moved daghash from dagconfig to util (#298)
* [NOD-176] Moved daghash from dagconfig to util

* [NOD-176] Fixed order of includes with gofmt
2019-05-14 14:05:36 +03:00
Ori Newman
ea5e18ea11 [NOD-96] Convert txid to pointer where possible (#279)
* [NOD-96] Convert txid to pointer where possible

* [NOD-96] Make msgTx.TxID return a pointer

* [NOD-96] observedTransaction.id -> observedTransaction.txID
2019-05-02 10:54:18 +03:00
Ori Newman
1a2166cddf [NOD-101] Create a bucket for utxo diffs (#245)
* [NOD-101] Create a bucket for utxo diffs

* [NOD-101] Add error when diff data is not found

* [NOD-101] Fix serialization comment
2019-04-11 16:09:44 +03:00
Evgeny Khirin
7c30bc4301 [NOD-64] Remove subnetwork id supports all (#237)
* [NOD-64] Intermediate commit: need check tests on master

* [NOD-64] Commit before changing subnetwork IDS to new values

* [NOD-64] Fixed tests after changing subnetworks IDs constants

* [NOD-64] Extract duplicate code into functions

* [NOD-64] Renamed IsAllSubnetworks ==> IncludeAllSubnetworks
2019-04-03 17:03:48 +03:00
Svarog
a2b69a84f4 [NOD-48] Make wire.NewMsgTx recieve all paramaters that go into MsgTx, and compute what can be computed. (#216)
* [NOD-48] Update wire.NewMsgTx to recieve all fields in msgTx

* [NOD-48] Fix all compilation errors resulting from modification of wire.NewMsgTx

* [NOD-48] Calculate payloadHash iff subnetworkID is not native

* [NOD-48] Update all places the instantiate wire.MsgTx to use wire.NewMsgTx

* [NOD-48] Remove 'wire.' calls inside wire package

* [NOD-48] Made newMsgTx with all parameters private, and added a few public functions that take various arguments for all common use-cases

* [NOD-48] Explicitly pass SubnetworkIDNative instead of nil to newMsgTx

* [NOD-48] Remove option to pass nil to newMsgTx
2019-03-19 12:28:24 +02:00
Evgeny Khirin
a31c07e8f3 [NOD-59] Rename txEncodingExcludeSubnetworkData (#215) 2019-03-17 16:44:44 +02:00
Evgeny Khirin
ee44eb20de [NOD-49] Exclude payload from transaction hash (#212) 2019-03-17 11:59:44 +02:00
Ori Newman
1da045d1b9 [NOD-30] move wire.RandomUint64() and binarySerializer to util (#204)
* [NOD-30] move wire.RandomUint64() and binarySerializer to util

* [NOD-30] change const style
2019-03-12 13:03:08 +02:00
Evgeny Khirin
b4f50f4e48 [Nod-25] Add payload hash to wire transaction (#200)
* [NOD-25] Intermediate commit

* [NOD-25] Fixed tests crashes

* [NOD-25] Fixed tests

* [NOD-25] Removed temporary debug code

* [NOD-25] Fixed error message
2019-03-12 10:48:57 +02:00
Ori Newman
1e447432a7 [NOD-28] Move subnetwork consts to subnetworkid package (#197)
* [NOD-28] Move SubnetworkID constants to subnetworkid package

* [NOD-28] change subnetwork id constants to pointers
2019-03-10 12:27:06 +02:00
Ori Newman
aa46c167c8 [NOD-46] Immediately associate received address to their subnetwork (#196)
* [NOD-46] Immediately associate received address to their subnetwork

* [NOD-46] fix comment

* [NOD-46] Disconnect peer if it sends an MsgAddr with no subnetwork

* [NOD-46] Disconnect peer if it sends an MsgAddr with incorrect subnetwork id

* [NOD-46] add parenthesis to condition

* [NOD-46] change order of conditions
2019-03-07 16:33:10 +02:00
Svarog
58b1b01c3f Dev 378 optimize calculate fee (#189)
* [DEV-378] Added feeAccumulator structures

* [DEV-378] Added logic to create and store fee data when validating a block

* [DEV-378] Renamed feeAccumulator to compactFeeData, and all related entities accordingly

* [DEV-378] Converted MsgTx.TxHash() to pointer to hash and not hash

* [DEV-378] Restructured parameters to buildFeeTransaction and related entities

* [DEV-378] Finished the code that calculates fees for blocks

* [DEV-378] Fix TxIndex after changing the structure of AcceptedTxsData

* [DEV-378] For genesis block: Return empty AcceptedTxsData instead of nil

* [DEV-378] Off-by-one error

* [DEV-378] Length of compactFeeData should be determined by specific method, not

* [DEV-378] Multiple bugfixes in tx fee calculation

* [DEV-378] Calculate fee even if fastAdd, to save feeData

* [DEV-378] use IsEqual instead of == when comparing TxHash

* [DEV-378] txindex: if including block is the new block - don't fetch id from DB

* [DEV-378] Fixed a few typos and made some vars consts

* [DEV-378] Re-organized fee functions, removed redundant functions and constants, and revised a few comments

* [DEV-378] Recovered fmt string changes lost in merge

* [DEV-378] Renamed acceptedTxsData and related types and vars to txsAcceptanceData

* [DEV-378] Some comment fixes

* [DEV-378] Remove redundant .ToString()
2019-02-24 11:52:06 +02:00
Svarog
41647fd488 [DEV-376] Changed any instance of %v in format strings with a more specific format token (#188)
* [DEV-376] Changed any instance of %v in format strings with a more specific format token

* [DEV-376] Fixed some more wrong formatting strings + removed redundant
cast

* [DEV-376] Added fmt.Sprintf where it was missing

* [DEV-376] use %s for util.Amount, to invoke .String()

* [DEV-376] Some more fixes in format strings

* [DEV-376] fixed mruinvmap_test to expect the correct behaviour
2019-02-20 14:02:52 +02:00
Ori Newman
0aa7c430e0 Dev 364 implement the dag fee structure (#181)
* [DEV-364] Add fee transactions validation

* [DEV-364] make NextBlockFeeTransactions for creating block templates

* [DEV-364] apply coinbase rules to fee transaction is some cases

* [DEV-364] Add comments

* [DEV-364] put getTXO as separate function

* [DEV-364] Make getParentsFeeData a separate function

* [DEV-364] fix calculateFees

* [DEV-364] force maximum sequence for fee transactions

* [DEV-364] add TestValidateFeeTransactions

* [DEV-364] change fee transaction to be one tx per block rather than one tx for each blue

* [DEV-364] fix tests

* [DEV-364] Use constants instead of inline numbers
2019-02-11 17:33:55 +02:00
Ori Newman
1e09d470f7 [DEV-336] Update peer package to accommodate partial nodes (#176)
* [DEV-336] Split addresses in address manager by subnetwork id

* [DEV-336] Load DAG with subnetwork from the config file

* [DEV-336] Remove redundant checks in updateAddrNew and updateAddrTried
2019-01-28 13:55:58 +02:00
Evgeny Khirin
100fbbaaa4 [DEV-361] Create type TxID as alias to daghash.Hash. (#175)
* [DEV-361] Create type TxID as alias to daghash.Hash. Use it for transaction IDs

* [DEV-361] Fixed missed renames

* [DEV-361] Removed usage of zeroHash

* [DEV-361] Fixed more missed renames
2019-01-27 14:27:10 +02:00
Ori Newman
b963c0d364
Dev 334 make id merkle root and transaction id, fix tests, and add new tests (#166)
* [DEV-329] Add TxID

* [DEV-329] Change Transaction inputs to reference by tx id instead of tx hash

* [DEV-329] Fix tests

* [DEV-329] change txhash to txid in mempool

* [DEV-334] Make IDMerkleRoot

* [DEV-329] Add txid that excludes payload, gas and ScriptSigs (#158)

* [DEV-329] Add TxID

* [DEV-329] Change Transaction inputs to reference by tx id instead of tx hash

* [DEV-329] Fix tests

* [DEV-329] change txhash to txid in mempool

* [DEV-329] replace thinEncoding bool with txEncoding bitmask

* [DEV-329] Change txencoding var names

* [DEV-329] change txEncodingexcludeSignatureScript -> txEncodingExcludeSignatureScript

* [DEV-334] Add IDMerkleRoot to blocknode and recalculate IDMerkleRoot when extraNonce is changed

* [DEV-334] Fix tests

* [DEV-334] Fix tests

* [DEV-334] fix SubnetworkDAGCoin -> SubnetworkIDNative

* [DEV-334] Add ID() function to Coin interface and rename hash to txID in a few places

* [DEV-334] Add Root method for merkle root

* [DEV-334] add comment to dag.SubnetworkID()

* [DEV-334] fix serializeSize comment
2019-01-23 14:04:23 +02:00
stasatdaglabs
4be23bff07 [DEV-348] Don't send transactions of wrong sub-network to partial peers, and reject messages of such (#164)
* [DEV-348] Removed a couple of unused methods.

* [DEV-348] Implemented validating incoming transactions for bad partial transactions.

* [DEV-348] Added a (incomplete) filter for propogation of transactions.

* [DEV-348] Implemented filtering inventory by subnetwork.

* [DEV-348] Fixed broken tests.

* [DEV-348] Added test for non-zero payload partial transactions.

* [DEV-348] Added a comment for Config.SubnetworkID.

* [DEV-348] Fixed formatting.

* [DEV-348] Renamed isRemoteTransactionFull to shouldTxBeFull.

* [DEV-348] Added a check for invalid transaction in maybeAcceptTransaction. Added handling for native networks.

* [DEV-348] Fixed formatting.

* [DEV-348] Fixed a bug in transaction validation.

* [DEV-348] Rephrased a comment.

* [DEV-348] Extracted subnetwork compatibility to a method. Wrote a test for it.

* [DEV-348] Removed an unnecessary check over the native subnetwork.
2019-01-22 13:56:40 +02:00
stasatdaglabs
f00651c4e3 [DEV-353] Rename subnetwork to subnetworkID everywhere in the code except for the command line flag (#165)
* [DEV-353] Renamed subnetwork -> subnetworkID.

* [DEV-353] Renamed dagcoin -> native.
2019-01-20 16:22:25 +02:00
Svarog
e3994cddac [DEV-347] Normalize the way 'subnetwork' is capitalized (#161) 2019-01-13 18:00:34 +02:00
Svarog
6b55950901 [DEV-345] Enforce requirement for transactions from 1(DAGCoin) or 2(sub network registry) sub network to have gas = 0 (#157)
* [DEV-345] Validate that gas and payload are 0 when required by sub-network

* [DEV-345] Remove check for txOut.Value < 0, since txOut.Value is a uint64

* [DEV-345] Added tests for CheckTransactionSanity

* [DEV-345] Remove checks for Gas and Payload validity in wire.MsgTx.Decode

* [DEV-345] Verify that payload in Gas sub-network is always 8 bytes (uint64).

* [DEV-345] Renamed tstCheck{Script/Rule}Error to check{Script/Rule}Error

* [DEV-345] Improved formatting
2019-01-13 11:01:43 +02:00
stasatdaglabs
5171d26bba [DEV-343] Change SubNetworkRegistry to use SubNetworkID as Hash160 (#156)
* [DEV-343] Made sub-network registry use subNetworkIDs.

* [DEV-343] Removed an unnecessary clone.

* [DEV-343] Renamed buildSubNetworkID to txToSubNetworkID. Broke out of a loop when it was known that no further processing is required. Handled error cases from dbGetNetwork separately from the "not-found" case/

* [DEV-343] Added an error case in GasLimit() for where the sub-network is nil.

* [DEV-343] Fixed return nil instead of err. Used a better way to check whether we should continue checking accepted transactions.
2019-01-10 17:13:11 +02:00
Ori Newman
0553f7e2e7 [DEV-342] change subnetworkid to hash160 (#154)
* [DEV-342] Make subnetworkid Hash160

* [DEV-342] Fix tests

* [DEV-342] Fix rpcserver.go mismatched types

* [DEV-342] Change subnetworkhash type and package to subnetworkid

* [DEV-342] Add subnetworkid package
2019-01-09 17:55:25 +02:00
stasatdaglabs
d33d633e77 [DEV-307] Create the sub-network registry (#147)
* [DEV-307] Implemented adding pending registry transactions.

* [DEV-307] Implemented a skeleton for the sub-network registry algorithm.

* [DEV-307] Implemented the serialization/deserialization logic for pending sub-network transactions.

* [DEV-307] Implemented marking sub-network registry transactions as successfully registered.

* [DEV-307] Implemented clearing pending sub-network entries and writing registered sub-networks.

* [DEV-307] Added comments for all the dagio functions.

* [DEV-307] Fixed a couple of bugs and added a test for checking serialization/deserialization of pending sub-network transactions.

* [DEV-307] Implemented getting a registered sub-network's gas limit.

* [DEV-307] Updated sub-network announcement transaction validation rules.

* [DEV-307] Specified what is validated.

* [DEV-307] Added initialization for lastSubNetworkID.

* [DEV-307] Renamed extractValidSubNetworkRegistryTxs to validateAndExtractSubNetworkRegistryTxs to better reflect what it does.

* Dev 303 implement block finality (#139)

* [DEV-303] Implement block finality

* [DEV-303] Add finality tests

* [DEV-303] Make finality tests use maybeAcceptBlock

* [DEV-303] Only check finality rules if we are fastAdd mode

* [DEV-303] replace hasBiggerFinalityScoreThan checks with .finalityScore()

* [DEV-307] Forgot to actually create the sub-network buckets.

* [DEV-307] Wrote a full-flow test for sub-network registry and fixed a couple of bugs that it had uncovered.

* [DEV-307] Took firstSubNetworkID out of dagconfig.Params. It's unnecessary there.

* [DEV-307] Added persistance for dag.lastSubNetworkID.

* [DEV-307] Moved sub-network stuff to their own files. Got rid of firstSubNetworkID. Replaced SubNetworkReservedLast with SubNetworkUnreservedFirst. Added ErrSubNetworkRegistry.

* [DEV-307] Added a newline at the end of dag_test.go.

* [DEV-307] Renamed previousFinalityPoint to initialFinalityPoint.

* [DEV-307] Moved sub-network IO stuff to subnetworks.go and subnetworks_test.go.

* [DEV-307] Merged dbPutRegisteredSubNetworkTx and dbRegisterSubNetwork. Fixed a too-big allocation and a block double-processing bug.

* [DEV-307] Simplified the serialized representation of a slice of transactions.

* [DEV-307] Fixed comments.
2019-01-07 17:10:23 +02:00
Svarog
ade33a94f3 [DEV-331] Disallowed node to run in reserved sub-networks (#148)
* [DEV-331] Disallowed node to run in reserved sub-networks

* [DEV-331] Added test to make sure that constant are not modified without modifying help text
2019-01-06 16:15:37 +02:00
Ori Newman
4a6fd8fad1 [DEV-320] add decoupling related fields to wire tx (#134)
* [DEV-320] Add decoupling-related fields to wire.Tx

* [DEV-320] Fix SerializeSize for MsgTx

* [DEV-320] Fix indexers test

* [DEV-320] Fix utils test

* [DEV-320] Fix ffldb tests

* [DEV-320] Fix mining tests

* [DEV-320] fix txsort tests

* [DEV-320] change default subnetwork id to 1 and remove payload for default subnetwork id

* [DEV-320] Add msgtx serialization tests

* [DEV-320] get rid of temp prints, and change error messages
2018-12-27 17:43:25 +02:00
Evgeny Khirin
499adbf046 DEV-222: Changed type of TxOut.Value and util.Amount to uin64 (#108)
* [DEV-222] Changed type of TxOut.Value and util.Amount to uin64

* [DEV-222] Replaced math.MaxUint64 with 0

* [DEV-222] Fixed comment to reflect uint64 instead of int64

* [DEV-222] Fixed overflow comment
2018-10-24 16:29:50 +03:00
Svarog
2068ac299a [DEV-77] Wire converage
* [DEV-77] Added tests for ScriptFreeList

* [DEV-77] Fixed formatting in BlockHeader .SelectedPrevBlock and IsGenesis

* [DEV-77] Restructured returnScriptBuffers to be more idiomatic and testable

* [DEV-77] Added tests for binaryFreeList

* [DEV-77] Added test-cases to TestVarIntWireErrors to check for errors when writing the varint length

* [DEV-77] Added MsgSendHeaders and MsgFeeFilter test-cases for TestMessage

* [DEV-77] Added test for BlockHeader.IsGenesis()

* [DEV-77] using binaryFreeListMaxItems instead of freeListMaxItems in TestBinaryFreeList

* [DEV-77] Fixed error message copy-paste typo
2018-07-29 14:32:28 +03:00
Ori Newman
1e98d0dbfe [DEV-31] remove json transaction tests 2018-07-22 15:53:06 +03:00
Ori Newman
29f1b2baff [DEV-31] Regenrate block databases and genesis blocks in order to be compatiable with the new structure (uint64 timestamps) 2018-07-19 19:04:00 +03:00
Ori Newman
0878f98d1e [DEV-31] Convert all timestamp to uint64 2018-07-17 13:04:29 +03:00
Ori Newman
d488aebe0d [DEV-31] Convert all timestamp to int64 2018-07-15 18:00:21 +03:00
Stas Boutenko
a26fd21ae7 [DEV-32] Renamed chaincfg to dagconfig and chainhash to daghash. 2018-06-19 18:19:54 +03:00
Mike Zak
9d6ea58b4c [DEV-14] Removed Segwit from wire package. 2018-06-13 11:20:46 +03:00
Stas Boutenko
2901d302f3 Updated references. 2018-06-03 18:34:09 +03:00
Dave Collins
a59ac5b18f
multi: Rework utxoset/view to use outpoints.
This modifies the utxoset in the database and related UtxoViewpoint to
store and work with unspent transaction outputs on a per-output basis
instead of at a transaction level.  This was inspired by similar recent
changes in Bitcoin Core.

The primary motivation is to simplify the code, pave the way for a
utxo cache, and generally focus on optimizing runtime performance.

The tradeoff is that this approach does somewhat increase the size of
the serialized utxoset since it means that the transaction hash is
duplicated for each output as a part of the key and some additional
details such as whether the containing transaction is a coinbase and the
block height it was a part of are duplicated in each output.

However, in practice, the size difference isn't all that large, disk
space is relatively cheap, certainly cheaper than memory, and it is much
more important to provide more efficient runtime operation since that is
the ultimate purpose of the daemon.

While performing this conversion, it also simplifies the code to remove
the transaction version information from the utxoset as well as the
spend journal.  The logic for only serializing it under certain
circumstances is complicated and it isn't actually used anywhere aside
from the gettxout RPC where it also isn't used by anything important
either.  Consequently, this also removes the version field of the
gettxout RPC result.

The utxos in the database are automatically migrated to the new format
with this commit and it is possible to interrupt and resume the
migration process.

Finally, it also updates the tests for the new format and adds a new
function to the tests to convert the old test data to the new format for
convenience.  The data has already been converted and updated in the
commit.

An overview of the changes are as follows:

- Remove transaction version from both spent and unspent output entries
  - Update utxo serialization format to exclude the version
  - Modify the spend journal serialization format
    - The old version field is now reserved and always stores zero and
      ignores it when reading
    - This allows old entries to be used by new code without having to
      migrate the entire spend journal
  - Remove version field from gettxout RPC result
- Convert UtxoEntry to represent a specific utxo instead of a
  transaction with all remaining utxos
  - Optimize for memory usage with an eye towards a utxo cache
    - Combine details such as whether the txout was contained in a
      coinbase, is spent, and is modified into a single packed field of
      bit flags
    - Align entry fields to eliminate extra padding since ultimately
      there will be a lot of these in memory
    - Introduce a free list for serializing an outpoint to the database
      key format to significantly reduce pressure on the GC
  - Update all related functions that previously dealt with transaction
    hashes to accept outpoints instead
  - Update all callers accordingly
  - Only add individually requested outputs from the mempool when
    constructing a mempool view
- Modify the spend journal to always store the block height and coinbase
  information with every spent txout
  - Introduce code to handle fetching the missing information from
    another utxo from the same transaction in the event an old style
    entry is encountered
    - Make use of a database cursor with seek to do this much more
      efficiently than testing every possible output
- Always decompress data loaded from the database now that a utxo entry
  only consists of a specific output
- Introduce upgrade code to migrate the utxo set to the new format
  - Store versions of the utxoset and spend journal buckets
  - Allow migration process to be interrupted and resumed
- Update all tests to expect the correct encodings, remove tests that no
  longer apply, and add new ones for the new expected behavior
  - Convert old tests for the legacy utxo format deserialization code to
    test the new function that is used during upgrade
  - Update the utxostore test data and add function that was used to
    convert it
- Introduce a few new functions on UtxoViewpoint
  - AddTxOut for adding an individual txout versus all of them
  - addTxOut to handle the common code between the new AddTxOut and
    existing AddTxOuts
  - RemoveEntry for removing an individual txout
  - fetchEntryByHash for fetching any remaining utxo for a given
    transaction hash
2018-05-27 03:07:41 -05:00
Nicola 'tekNico' Larosa
11fcd83963 btcd/multi: fix a number of typos in comments. 2018-01-25 23:23:59 -06:00
Olaoluwa Osuntokun
1d01c657dd BIP0141+wire: add a WitnessHash method to tx 2017-08-13 23:17:40 -05:00
Olaoluwa Osuntokun
98cae74275 BIP0143+txscript: add segwit sighash, signing, and HashCache integration
This commit implements most of BIP0143 by adding logic to implement the
new sighash calculation, signing, and additionally introduces the
HashCache optimization which eliminates the O(N^2) computational
complexity for the SIGHASH_ALL sighash type.

The HashCache struct is the equivalent to the existing SigCache struct,
but for caching the reusable midstate for transactions which are
spending segwitty outputs.
2017-08-13 23:17:40 -05:00
Olaoluwa Osuntokun
192bfbf123 BIP0144+wire: implement witness encoding/decoding for transactions
This commit implements the new witness encoding/decoding for
transactions as specified by BIP0144. After segwit activation, a
special transaction encoding is used to signal to upgraded nodes that
the transaction being deserialized bares witness data. The prior
BtcEncode and BtcDecode methods have been extended to be aware of the
new signaling bytes and the encoding of witness data within
transactions.

Additionally, a new method has been added to calculate the “stripped
size” of a transaction/block which is defined as the size of a
transaction/block *excluding* any witness data.
2017-08-13 23:17:40 -05:00