From df701d8cdfbbea6af4af39db85eec3b7269fa0ac Mon Sep 17 00:00:00 2001 From: cjepson Date: Tue, 8 Mar 2016 22:16:06 -0500 Subject: [PATCH] Revert sync merge The sync merge does not build and needs further testing. It is being reverted. --- blockchain/accept.go | 10 +- blockchain/blocklocator.go | 6 +- blockchain/chain.go | 36 ++-- blockchain/checkpoints.go | 2 +- blockchain/common.go | 6 +- blockchain/common_test.go | 4 +- blockchain/difficulty.go | 22 +-- blockchain/notifications.go | 6 +- blockchain/reorganization_test.go | 12 +- blockchain/stake/ticketdb.go | 58 +++---- blockchain/stake/ticketdb_test.go | 6 +- blockchain/subsidy.go | 14 +- blockchain/subsidy_test.go | 6 +- blockchain/ticketlookup.go | 8 +- blockchain/txlookup.go | 6 +- blockchain/validate.go | 26 +-- blockchain/validate_test.go | 162 +++++++++--------- blockmanager.go | 34 ++-- chaincfg/params.go | 12 +- chainindexer.go | 6 +- cmd/dropafter/dropafter.go | 4 +- cmd/findcheckpoint/findcheckpoint.go | 4 +- cmd/showblock/showblock.go | 12 +- cpuminer.go | 4 +- database/common_test.go | 4 +- database/db.go | 20 +-- database/interface_test.go | 14 +- database/ldb/block.go | 44 ++--- database/ldb/dup_test.go | 2 +- database/ldb/insertremove_test.go | 4 +- database/ldb/leveldb.go | 16 +- database/ldb/operational_test.go | 28 ++-- database/ldb/tx.go | 26 +-- database/memdb/memdb.go | 34 ++-- database/reorg_test.go | 14 +- dcrjson/chainsvrcmds.go | 16 -- dcrjson/chainsvrcmds_test.go | 17 +- dcrjson/chainsvrresults.go | 32 +--- dcrjson/walletsvrcmds.go | 10 -- dcrjson/walletsvrcmds_test.go | 13 +- doc.go | 2 - docs/code_contribution_guidelines.md | 47 ------ docs/json_rpc_api.md | 44 +---- mempool.go | 33 ++-- mining.go | 16 +- peer.go | 66 ++++---- rpcserver.go | 236 +++++++++------------------ rpcserverhelp.go | 30 ---- rpcwebsocket.go | 36 ++-- sample-dcrd.conf | 27 --- server.go | 6 +- txscript/error.go | 26 +-- txscript/opcode.go | 2 +- txscript/script.go | 28 ++-- txscript/script_test.go | 35 ---- txscript/standard.go | 2 +- wire/blockheader.go | 16 -- wire/blockheader_test.go | 24 +-- 58 files changed, 539 insertions(+), 897 deletions(-) diff --git a/blockchain/accept.go b/blockchain/accept.go index 1cbc1780..92e4d640 100644 --- a/blockchain/accept.go +++ b/blockchain/accept.go @@ -19,7 +19,7 @@ import ( // checkCoinbaseUniqueHeight checks to ensure that for all blocks height > 1 // that the coinbase contains the height encoding to make coinbase hash collisions // impossible. -func checkCoinbaseUniqueHeight(blockHeight int32, block *dcrutil.Block) error { +func checkCoinbaseUniqueHeight(blockHeight int64, block *dcrutil.Block) error { if !(len(block.MsgBlock().Transactions) > 0) { str := fmt.Sprintf("block %v has no coinbase", block.Sha()) return ruleError(ErrNoTransactions, str) @@ -67,7 +67,7 @@ func checkCoinbaseUniqueHeight(blockHeight int32, block *dcrutil.Block) error { } // IsFinalizedTransaction determines whether or not a transaction is finalized. -func IsFinalizedTransaction(tx *dcrutil.Tx, blockHeight int32, +func IsFinalizedTransaction(tx *dcrutil.Tx, blockHeight int64, blockTime time.Time) bool { msgTx := tx.MsgTx() @@ -83,7 +83,7 @@ func IsFinalizedTransaction(tx *dcrutil.Tx, blockHeight int32, // threshold it is a block height. blockTimeOrHeight := int64(0) if lockTime < txscript.LockTimeThreshold { - blockTimeOrHeight = int64(blockHeight) + blockTimeOrHeight = blockHeight } else { blockTimeOrHeight = blockTime.Unix() } @@ -153,7 +153,7 @@ func (b *BlockChain) checkBlockContext(block *dcrutil.Block, prevNode *blockNode // Check that the node is at the correct height in the blockchain, // as specified in the block header. - if blockHeight != int32(block.MsgBlock().Header.Height) { + if blockHeight != int64(block.MsgBlock().Header.Height) { errStr := fmt.Sprintf("Block header height invalid; expected %v"+ " but %v was found", blockHeight, header.Height) return ruleError(ErrBadBlockHeight, errStr) @@ -194,7 +194,7 @@ func (b *BlockChain) maybeAcceptBlock(block *dcrutil.Block, // The height of this block is one more than the referenced previous // block. - blockHeight := int32(0) + blockHeight := int64(0) if prevNode != nil { blockHeight = prevNode.height + 1 } diff --git a/blockchain/blocklocator.go b/blockchain/blocklocator.go index 7da8280c..4f35e78e 100644 --- a/blockchain/blocklocator.go +++ b/blockchain/blocklocator.go @@ -50,8 +50,8 @@ func (b *BlockChain) BlockLocatorFromHash(hash *chainhash.Hash) BlockLocator { // Attempt to find the height of the block that corresponds to the // passed hash, and if it's on a side chain, also find the height at // which it forks from the main chain. - blockHeight := int32(-1) - forkHeight := int32(-1) + blockHeight := int64(-1) + forkHeight := int64(-1) node, exists := b.index[*hash] if !exists { // Try to look up the height for passed block hash. Assume an @@ -82,7 +82,7 @@ func (b *BlockChain) BlockLocatorFromHash(hash *chainhash.Hash) BlockLocator { // in the BlockLocator comment and make sure to leave room for the // final genesis hash. iterNode := node - increment := int32(1) + increment := int64(1) for len(locator) < wire.MaxBlockLocatorsPerMsg-1 { // Once there are 10 locators, exponentially increase the // distance between each block locator. diff --git a/blockchain/chain.go b/blockchain/chain.go index d737bf11..313a91fb 100644 --- a/blockchain/chain.go +++ b/blockchain/chain.go @@ -65,7 +65,7 @@ type blockNode struct { parentHash *chainhash.Hash // height is the position in the block chain. - height int32 + height int64 // workSum is the total amount of work in the chain up to and including // this node. @@ -100,7 +100,7 @@ type blockNode struct { // for the passed block. The work sum is updated accordingly when the node is // inserted into a chain. func newBlockNode(blockHeader *wire.BlockHeader, blockSha *chainhash.Hash, - height int32, voteBits []uint16) *blockNode { + height int64, voteBits []uint16) *blockNode { // Make a copy of the hash so the node doesn't keep a reference to part // of the full block/block header preventing it from being garbage // collected. @@ -167,11 +167,11 @@ type BlockChain struct { db database.Db tmdb *stake.TicketDB chainParams *chaincfg.Params - checkpointsByHeight map[int32]*chaincfg.Checkpoint + checkpointsByHeight map[int64]*chaincfg.Checkpoint notifications NotificationCallback - minMemoryNodes int32 + minMemoryNodes int64 blocksPerRetarget int64 - stakeValidationHeight int32 + stakeValidationHeight int64 root *blockNode bestChain *blockNode index map[chainhash.Hash]*blockNode @@ -190,7 +190,7 @@ type BlockChain struct { // StakeValidationHeight returns the height at which proof of stake validation // begins for proof of work block headers. -func (b *BlockChain) StakeValidationHeight() int32 { +func (b *BlockChain) StakeValidationHeight() int64 { return b.stakeValidationHeight } @@ -504,7 +504,7 @@ func (b *BlockChain) GenerateInitialIndex() error { // Start at the next block after the latest one on the next loop // iteration. - start += int32(len(hashList)) + start += int64(len(hashList)) } return nil @@ -529,7 +529,7 @@ func (b *BlockChain) loadBlockNode(hash *chainhash.Hash) (*blockNode, error) { } } node := newBlockNode(&block.MsgBlock().Header, hash, - int32(block.MsgBlock().Header.Height), voteBitsStake) + int64(block.MsgBlock().Header.Height), voteBitsStake) node.inMainChain = true prevHash := &block.MsgBlock().Header.PrevBlock @@ -696,7 +696,7 @@ func (b *BlockChain) getPrevNodeFromNode(node *blockNode) (*blockNode, error) { // the node with a desired block height; it returns this block. The benefit is // this works for both the main chain and the side chain. func (b *BlockChain) getNodeAtHeightFromTopNode(node *blockNode, - toTraverse int32) (*blockNode, error) { + toTraverse int64) (*blockNode, error) { oldNode := node var err error @@ -812,7 +812,7 @@ func (b *BlockChain) pruneBlockNodes() error { // the latter loads the node and the goal is to find nodes still in // memory that can be pruned. newRootNode := b.bestChain - for i := int32(0); i < b.minMemoryNodes-1 && newRootNode != nil; i++ { + for i := int64(0); i < b.minMemoryNodes-1 && newRootNode != nil; i++ { newRootNode = newRootNode.parent } @@ -1089,8 +1089,8 @@ func (b *BlockChain) disconnectBlock(node *blockNode, block *dcrutil.Block) erro // Insert block into ticket database if we're the point where tickets begin to // mature. - maturityHeight := int32(b.chainParams.TicketMaturity) + - int32(b.chainParams.CoinbaseMaturity) + maturityHeight := int64(b.chainParams.TicketMaturity) + + int64(b.chainParams.CoinbaseMaturity) // Remove from ticket database. if node.height-1 >= maturityHeight { @@ -1551,9 +1551,9 @@ func maxInt64(a, b int64) int64 { func New(db database.Db, tmdb *stake.TicketDB, params *chaincfg.Params, c NotificationCallback) *BlockChain { // Generate a checkpoint by height map from the provided checkpoints. - var checkpointsByHeight map[int32]*chaincfg.Checkpoint + var checkpointsByHeight map[int64]*chaincfg.Checkpoint if len(params.Checkpoints) > 0 { - checkpointsByHeight = make(map[int32]*chaincfg.Checkpoint) + checkpointsByHeight = make(map[int64]*chaincfg.Checkpoint) for i := range params.Checkpoints { checkpoint := ¶ms.Checkpoints[i] checkpointsByHeight[checkpoint.Height] = checkpoint @@ -1563,10 +1563,10 @@ func New(db database.Db, tmdb *stake.TicketDB, params *chaincfg.Params, // BlocksPerRetarget is the number of blocks between each difficulty // retarget. It is calculated based on the retargeting window sizes // in blocks for both PoW and PoS. - blocksPerRetargetPoW := int64(params.WorkDiffWindowSize) * - params.WorkDiffWindows - blocksPerRetargetPoS := int64(params.StakeDiffWindowSize) * - params.StakeDiffWindows + blocksPerRetargetPoW := int64(params.WorkDiffWindowSize * + params.WorkDiffWindows) + blocksPerRetargetPoS := int64(params.StakeDiffWindowSize * + params.StakeDiffWindows) blocksPerRetarget := maxInt64(blocksPerRetargetPoW, blocksPerRetargetPoS) b := BlockChain{ diff --git a/blockchain/checkpoints.go b/blockchain/checkpoints.go index 7132da1a..24ae0547 100644 --- a/blockchain/checkpoints.go +++ b/blockchain/checkpoints.go @@ -60,7 +60,7 @@ func (b *BlockChain) LatestCheckpoint() *chaincfg.Checkpoint { // verifyCheckpoint returns whether the passed block height and hash combination // match the hard-coded checkpoint data. It also returns true if there is no // checkpoint data for the passed block height. -func (b *BlockChain) verifyCheckpoint(height int32, hash *chainhash.Hash) bool { +func (b *BlockChain) verifyCheckpoint(height int64, hash *chainhash.Hash) bool { if b.noCheckpoints || len(b.chainParams.Checkpoints) == 0 { return true } diff --git a/blockchain/common.go b/blockchain/common.go index 8204eec8..64f93ad3 100644 --- a/blockchain/common.go +++ b/blockchain/common.go @@ -360,7 +360,7 @@ func DebugTicketDBLiveBucketString(tmdb *stake.TicketDB, bucket uint8, verbose b // DebugTicketDBSpentBucketString prints the contents of the spent tickets // database bucket indicated to a string that is returned. If the verbose // flag is indicated, the contents of each ticket are printed as well. -func DebugTicketDBSpentBucketString(tmdb *stake.TicketDB, height int32, verbose bool) (string, error) { +func DebugTicketDBSpentBucketString(tmdb *stake.TicketDB, height int64, verbose bool) (string, error) { var buffer bytes.Buffer str := fmt.Sprintf("Contents of spent ticket bucket height %v:\n", height) @@ -514,7 +514,7 @@ func TicketDbThumbprint(tmdb *stake.TicketDB, chainParams *chaincfg.Params) ([]* height := tmdb.GetTopBlock() allSpentTickets := stake.NewTicketDataSliceEmpty() - for i := int32(chainParams.StakeEnabledHeight); i <= height; i++ { + for i := int64(chainParams.StakeEnabledHeight); i <= height; i++ { bucketTickets, err := tmdb.DumpSpentTickets(i) if err != nil { return nil, err @@ -567,7 +567,7 @@ func TicketDbThumbprint(tmdb *stake.TicketDB, chainParams *chaincfg.Params) ([]* // VERY INTENSIVE BLOCKCHAIN SCANNING, USE TO DEBUG SIMULATED BLOCKCHAINS // ONLY. func (b *BlockChain) findWhereDoubleSpent(block *dcrutil.Block) error { - height := int32(1) + height := int64(1) heightEnd := block.Height() hashes, err := b.db.FetchHeightRange(height, heightEnd) diff --git a/blockchain/common_test.go b/blockchain/common_test.go index 55ff2aa3..7065060e 100644 --- a/blockchain/common_test.go +++ b/blockchain/common_test.go @@ -115,7 +115,7 @@ func chainSetup(dbName string, params *chaincfg.Params) (*blockchain.BlockChain, // Insert the main network genesis block. This is part of the initial // database setup. genesisBlock := dcrutil.NewBlock(params.GenesisBlock) - genesisBlock.SetHeight(int32(0)) + genesisBlock.SetHeight(int64(0)) _, err := db.InsertBlock(genesisBlock) if err != nil { teardown() @@ -195,7 +195,7 @@ func loadTxStore(filename string) (blockchain.TxStore, error) { if err != nil { return nil, err } - txD.BlockHeight = int32(uintBuf) + txD.BlockHeight = int64(uintBuf) // Num spent bits. err = binary.Read(r, binary.LittleEndian, &uintBuf) diff --git a/blockchain/difficulty.go b/blockchain/difficulty.go index 517cc172..7cc4e580 100644 --- a/blockchain/difficulty.go +++ b/blockchain/difficulty.go @@ -207,7 +207,7 @@ func (b *BlockChain) findPrevTestNetDifficulty(startNode *blockNode) (uint32, // Search backwards through the chain for the last block without // the special rule applied. blocksPerRetarget := b.chainParams.WorkDiffWindowSize * - int32(b.chainParams.WorkDiffWindows) + b.chainParams.WorkDiffWindows iterNode := startNode for iterNode != nil && iterNode.height%blocksPerRetarget != 0 && iterNode.bits == b.chainParams.PowLimitBits { @@ -311,8 +311,8 @@ func (b *BlockChain) calcNextRequiredDifficulty(curNode *blockNode, alpha := b.chainParams.WorkDiffAlpha // Number of nodes to traverse while calculating difficulty. - nodesToTraverse := b.chainParams.WorkDiffWindowSize * - int32(b.chainParams.WorkDiffWindows) + nodesToTraverse := (b.chainParams.WorkDiffWindowSize * + b.chainParams.WorkDiffWindows) // Initialize bigInt slice for the percentage changes for each window period // above or below the target. @@ -326,7 +326,7 @@ func (b *BlockChain) calcNextRequiredDifficulty(curNode *blockNode, recentTime := curNode.header.Timestamp.UnixNano() olderTime := int64(0) - for i := int32(0); ; i++ { + for i := int64(0); ; i++ { // Store and reset after reaching the end of every window period. if i%b.chainParams.WorkDiffWindowSize == 0 && i != 0 { olderTime = oldNode.header.Timestamp.UnixNano() @@ -484,14 +484,14 @@ func mergeDifficulty(oldDiff int64, newDiff1 int64, newDiff2 int64) int64 { func (b *BlockChain) calcNextRequiredStakeDifficulty(curNode *blockNode) (int64, error) { alpha := b.chainParams.StakeDiffAlpha - stakeDiffStartHeight := int32(b.chainParams.CoinbaseMaturity) + + stakeDiffStartHeight := int64(b.chainParams.CoinbaseMaturity) + 1 maxRetarget := int64(b.chainParams.RetargetAdjustmentFactor) TicketPoolWeight := int64(b.chainParams.TicketPoolSizeWeight) // Number of nodes to traverse while calculating difficulty. - nodesToTraverse := b.chainParams.StakeDiffWindowSize * - int32(b.chainParams.StakeDiffWindows) + nodesToTraverse := (b.chainParams.StakeDiffWindowSize * + b.chainParams.StakeDiffWindows) // Genesis block. Block at height 1 has these parameters. // Additionally, if we're before the time when people generally begin @@ -529,7 +529,7 @@ func (b *BlockChain) calcNextRequiredStakeDifficulty(curNode *blockNode) (int64, windowPeriod := int64(0) weights := uint64(0) - for i := int32(0); ; i++ { + for i := int64(0); ; i++ { // Store and reset after reaching the end of every window period. if (i+1)%b.chainParams.StakeDiffWindowSize == 0 { // First adjust based on ticketPoolSize. Skew the difference @@ -617,7 +617,7 @@ func (b *BlockChain) calcNextRequiredStakeDifficulty(curNode *blockNode) (int64, // The target number of new SStx per block for any given window period. targetForWindow := b.chainParams.StakeDiffWindowSize * - int32(b.chainParams.TicketsPerBlock) + int64(b.chainParams.TicketsPerBlock) // Regress through all of the previous blocks and store the percent changes // per window period; use bigInts to emulate 64.32 bit fixed point. @@ -626,7 +626,7 @@ func (b *BlockChain) calcNextRequiredStakeDifficulty(curNode *blockNode) (int64, windowPeriod = int64(0) weights = uint64(0) - for i := int32(0); ; i++ { + for i := int64(0); ; i++ { // Add the fresh stake into the store for this window period. windowFreshStake += int64(oldNode.header.FreshStake) @@ -639,7 +639,7 @@ func (b *BlockChain) calcNextRequiredStakeDifficulty(curNode *blockNode) (int64, freshTemp := big.NewInt(windowFreshStake) freshTemp.Lsh(freshTemp, 32) // Add padding - targetTemp := big.NewInt(int64(targetForWindow)) + targetTemp := big.NewInt(targetForWindow) // Get the percentage change. windowAdjusted := freshTemp.Div(freshTemp, targetTemp) diff --git a/blockchain/notifications.go b/blockchain/notifications.go index 943b2651..2f9f79b7 100644 --- a/blockchain/notifications.go +++ b/blockchain/notifications.go @@ -78,16 +78,16 @@ type BlockAcceptedNtfnsData struct { // about a reorganization. type ReorganizationNtfnsData struct { OldHash chainhash.Hash - OldHeight int32 + OldHeight int64 NewHash chainhash.Hash - NewHeight int32 + NewHeight int64 } // TicketNotificationsData is the structure for new/spent/missed ticket // notifications at blockchain HEAD that are outgoing from chain. type TicketNotificationsData struct { Hash chainhash.Hash - Height int32 + Height int64 StakeDifficulty int64 TicketMap stake.SStxMemMap } diff --git a/blockchain/reorganization_test.go b/blockchain/reorganization_test.go index d3cf7395..aad74b50 100644 --- a/blockchain/reorganization_test.go +++ b/blockchain/reorganization_test.go @@ -55,7 +55,7 @@ func TestReorganization(t *testing.T) { // Create decoder from the buffer and a map to store the data bcDecoder := gob.NewDecoder(bcBuf) - blockChain := make(map[int32][]byte) + blockChain := make(map[int64][]byte) // Decode the blockchain into the map if err := bcDecoder.Decode(&blockChain); err != nil { @@ -66,11 +66,11 @@ func TestReorganization(t *testing.T) { timeSource := blockchain.NewMedianTime() finalIdx1 := 179 for i := 1; i < finalIdx1+1; i++ { - bl, err := dcrutil.NewBlockFromBytes(blockChain[int32(i)]) + bl, err := dcrutil.NewBlockFromBytes(blockChain[int64(i)]) if err != nil { t.Errorf("NewBlockFromBytes error: %v", err.Error()) } - bl.SetHeight(int32(i)) + bl.SetHeight(int64(i)) _, _, err = chain.ProcessBlock(bl, timeSource, blockchain.BFNone) if err != nil { @@ -92,7 +92,7 @@ func TestReorganization(t *testing.T) { // Create decoder from the buffer and a map to store the data bcDecoder = gob.NewDecoder(bcBuf) - blockChain = make(map[int32][]byte) + blockChain = make(map[int64][]byte) // Decode the blockchain into the map if err := bcDecoder.Decode(&blockChain); err != nil { @@ -102,11 +102,11 @@ func TestReorganization(t *testing.T) { forkPoint := 131 finalIdx2 := 180 for i := forkPoint; i < finalIdx2+1; i++ { - bl, err := dcrutil.NewBlockFromBytes(blockChain[int32(i)]) + bl, err := dcrutil.NewBlockFromBytes(blockChain[int64(i)]) if err != nil { t.Errorf("NewBlockFromBytes error: %v", err.Error()) } - bl.SetHeight(int32(i)) + bl.SetHeight(int64(i)) _, _, err = chain.ProcessBlock(bl, timeSource, blockchain.BFNone) if err != nil { diff --git a/blockchain/stake/ticketdb.go b/blockchain/stake/ticketdb.go index 86f41d3a..c6d7cc44 100644 --- a/blockchain/stake/ticketdb.go +++ b/blockchain/stake/ticketdb.go @@ -57,7 +57,7 @@ type TicketData struct { SStxHash chainhash.Hash Prefix uint8 // Ticket hash prefix for pre-sort SpendHash chainhash.Hash - BlockHeight int32 // Block for where the original sstx was located + BlockHeight int64 // Block for where the original sstx was located Missed bool // Whether or not the ticket was spent Expired bool // Whether or not the ticket expired } @@ -66,7 +66,7 @@ type TicketData struct { func NewTicketData(sstxHash chainhash.Hash, prefix uint8, spendHash chainhash.Hash, - blockHeight int32, + blockHeight int64, missed bool, expired bool) *TicketData { return &TicketData{sstxHash, @@ -176,7 +176,7 @@ type SStxMemMap map[chainhash.Hash]*TicketData // ticket in-memory database. type TicketMaps struct { ticketMap []SStxMemMap - spentTicketMap map[int32]SStxMemMap + spentTicketMap map[int64]SStxMemMap missedTicketMap SStxMemMap revokedTicketMap SStxMemMap } @@ -232,7 +232,7 @@ type TicketDB struct { maps TicketMaps database database.Db chainParams *chaincfg.Params - StakeEnabledHeight int32 + StakeEnabledHeight int64 } // Initialize allocates buckets for each ticket number in ticketMap and buckets @@ -249,7 +249,7 @@ func (tmdb *TicketDB) Initialize(np *chaincfg.Params, db database.Db) { tmdb.chainParams = np tmdb.database = db tmdb.maps.ticketMap = make([]SStxMemMap, BucketsSize, BucketsSize) - tmdb.maps.spentTicketMap = make(map[int32]SStxMemMap) + tmdb.maps.spentTicketMap = make(map[int64]SStxMemMap) tmdb.maps.missedTicketMap = make(SStxMemMap) tmdb.maps.revokedTicketMap = make(SStxMemMap) @@ -266,7 +266,7 @@ func (tmdb *TicketDB) Initialize(np *chaincfg.Params, db database.Db) { // a lot of redundant calls, but I don't think they're expensive. // // This function MUST be called with the tmdb lock held (for writes). -func (tmdb *TicketDB) maybeInsertBlock(height int32) { +func (tmdb *TicketDB) maybeInsertBlock(height int64) { // Check if the bucket exists for the given height. if tmdb.maps.spentTicketMap[height] != nil { return @@ -281,7 +281,7 @@ func (tmdb *TicketDB) maybeInsertBlock(height int32) { // GetTopBlock. See the comment for GetTopBlock for more details. // // This function MUST be called with the tmdb lock held (for writes). -func (tmdb *TicketDB) getTopBlock() int32 { +func (tmdb *TicketDB) getTopBlock() int64 { // Discover the current height. topHeight := tmdb.StakeEnabledHeight for { @@ -294,7 +294,7 @@ func (tmdb *TicketDB) getTopBlock() int32 { // If we aren't yet at a stake mature blockchain. if topHeight == (tmdb.StakeEnabledHeight - 1) { - return int32(-1) + return int64(-1) } return topHeight } @@ -302,7 +302,7 @@ func (tmdb *TicketDB) getTopBlock() int32 { // GetTopBlock returns the top (current) block from a TicketDB. // // This function is safe for concurrent access. -func (tmdb *TicketDB) GetTopBlock() int32 { +func (tmdb *TicketDB) GetTopBlock() int64 { tmdb.mtx.Lock() defer tmdb.mtx.Unlock() @@ -393,7 +393,7 @@ func (tmdb *TicketDB) LoadTicketDBs(tmsPath, tmsLoc string, np *chaincfg.Params, } if tmdb.maps.spentTicketMap == nil { - tmdb.maps.spentTicketMap = make(map[int32]SStxMemMap) + tmdb.maps.spentTicketMap = make(map[int64]SStxMemMap) } if tmdb.maps.missedTicketMap == nil { @@ -483,7 +483,7 @@ func (tmdb *TicketDB) pushLiveTicket(ticket *TicketData) error { // pushSpentTicket pushes a used ticket into the spentTicketMap. // // This function MUST be called with the tmdb lock held (for writes). -func (tmdb *TicketDB) pushSpentTicket(spendHeight int32, ticket *TicketData) error { +func (tmdb *TicketDB) pushSpentTicket(spendHeight int64, ticket *TicketData) error { // Make sure there's a bucket in the map for used tickets tmdb.maybeInsertBlock(spendHeight) @@ -576,7 +576,7 @@ func (tmdb *TicketDB) removeLiveTicket(ticket *TicketData) error { // removeSpentTicket removes spent tickets that were added to the spentTicketMap. // // This function MUST be called with the tmdb lock held (for writes). -func (tmdb *TicketDB) removeSpentTicket(spendHeight int32, ticket *TicketData) error { +func (tmdb *TicketDB) removeSpentTicket(spendHeight int64, ticket *TicketData) error { // Make sure the height bucket exists; if it doesn't something has gone wrong // with the initialization if tmdb.maps.spentTicketMap[spendHeight] == nil { @@ -657,7 +657,7 @@ func (tmdb *TicketDB) removeRevokedTicket(ticket *TicketData) error { // removeSpentHeight removes a height bucket from the SpentTicketMap. // // This function MUST be called with the tmdb lock held (for writes). -func (tmdb *TicketDB) removeSpentHeight(height int32) error { +func (tmdb *TicketDB) removeSpentHeight(height int64) error { // Make sure the height exists if tmdb.maps.spentTicketMap[height] == nil { return fmt.Errorf("TicketDB err @ removeSpentHeight: height to "+ @@ -780,7 +780,7 @@ func (tmdb *TicketDB) DumpLiveTickets(bucket uint8) (SStxMemMap, error) { // spentTicketMap and returns them to the user. // // This function is safe for concurrent access. -func (tmdb *TicketDB) DumpSpentTickets(height int32) (SStxMemMap, error) { +func (tmdb *TicketDB) DumpSpentTickets(height int64) (SStxMemMap, error) { tmdb.mtx.Lock() defer tmdb.mtx.Unlock() @@ -1109,9 +1109,9 @@ func (tmdb *TicketDB) spendTickets(parentBlock *dcrutil.Block, // tickets map. // // This function MUST be called with the tmdb lock held (for writes). -func (tmdb *TicketDB) expireTickets(height int32) (SStxMemMap, error) { - toExpireHeight := height - int32(tmdb.chainParams.TicketExpiry) - if toExpireHeight < int32(tmdb.StakeEnabledHeight) { +func (tmdb *TicketDB) expireTickets(height int64) (SStxMemMap, error) { + toExpireHeight := height - int64(tmdb.chainParams.TicketExpiry) + if toExpireHeight < int64(tmdb.StakeEnabledHeight) { return nil, nil } @@ -1178,7 +1178,7 @@ func (tmdb *TicketDB) revokeTickets( // the missedTicketMap, then returns all these tickets in a map. // // This function MUST be called with the tmdb lock held (for writes). -func (tmdb *TicketDB) unrevokeTickets(height int32) (SStxMemMap, error) { +func (tmdb *TicketDB) unrevokeTickets(height int64) (SStxMemMap, error) { // Get the block of interest. var hash, errHash = tmdb.database.FetchBlockShaByHeight(height) if errHash != nil { @@ -1233,7 +1233,7 @@ func (tmdb *TicketDB) unrevokeTickets(height int32) (SStxMemMap, error) { // encountering and validating a fork. // // This function MUST be called with the tmdb lock held (for writes). -func (tmdb *TicketDB) unspendTickets(height int32) (SStxMemMap, error) { +func (tmdb *TicketDB) unspendTickets(height int64) (SStxMemMap, error) { tempTickets := make(SStxMemMap) for _, ticket := range tmdb.maps.spentTicketMap[height] { @@ -1284,14 +1284,14 @@ func (tmdb *TicketDB) unspendTickets(height int32) (SStxMemMap, error) { // SIDE CHAIN evaluation should be instantiated in package:chain. // // This function MUST be called with the tmdb lock held (for reads). -func (tmdb *TicketDB) getNewTicketsFromHeight(height int32) (SStxMemMap, error) { +func (tmdb *TicketDB) getNewTicketsFromHeight(height int64) (SStxMemMap, error) { if height < tmdb.StakeEnabledHeight { errStr := fmt.Sprintf("Tried to generate tickets for immature blockchain"+ " at height %v", height) return nil, errors.New(errStr) } - matureHeight := height - int32(tmdb.chainParams.TicketMaturity) + matureHeight := height - int64(tmdb.chainParams.TicketMaturity) var hash, errHash = tmdb.database.FetchBlockShaByHeight(matureHeight) if errHash != nil { @@ -1333,7 +1333,7 @@ func (tmdb *TicketDB) getNewTicketsFromHeight(height int32) (SStxMemMap, error) // looking them up in the database. // // This function MUST be called with the tmdb lock held (for writes). -func (tmdb *TicketDB) pushMatureTicketsAtHeight(height int32) (SStxMemMap, error) { +func (tmdb *TicketDB) pushMatureTicketsAtHeight(height int64) (SStxMemMap, error) { tempTickets := make(SStxMemMap) tickets, err := tmdb.getNewTicketsFromHeight(height) @@ -1480,7 +1480,7 @@ func (tmdb *TicketDB) InsertBlock(block *dcrutil.Block) (SStxMemMap, // looking them up in the database. // // Safe for concurrent access (does not use TicketDB maps directly). -func (tmdb *TicketDB) unpushMatureTicketsAtHeight(height int32) (SStxMemMap, +func (tmdb *TicketDB) unpushMatureTicketsAtHeight(height int64) (SStxMemMap, error) { tempTickets := make(SStxMemMap) @@ -1507,8 +1507,8 @@ func (tmdb *TicketDB) unpushMatureTicketsAtHeight(height int32) (SStxMemMap, // height. // // This function is safe for concurrent access. -func (tmdb *TicketDB) RemoveBlockToHeight(height int32) (map[int32]SStxMemMap, - map[int32]SStxMemMap, map[int32]SStxMemMap, error) { +func (tmdb *TicketDB) RemoveBlockToHeight(height int64) (map[int64]SStxMemMap, + map[int64]SStxMemMap, map[int64]SStxMemMap, error) { tmdb.mtx.Lock() defer tmdb.mtx.Unlock() @@ -1527,9 +1527,9 @@ func (tmdb *TicketDB) RemoveBlockToHeight(height int32) (map[int32]SStxMemMap, } // Create pseudo-DB maps of all the changes we're making - unmaturedTicketMap := make(map[int32]SStxMemMap) - unspentTicketMap := make(map[int32]SStxMemMap) - unrevokedTicketMap := make(map[int32]SStxMemMap) + unmaturedTicketMap := make(map[int64]SStxMemMap) + unspentTicketMap := make(map[int64]SStxMemMap) + unrevokedTicketMap := make(map[int64]SStxMemMap) // Iterates down from the top block, removing all changes that were made to // the stake db at that block, until it reaches the height specified. @@ -1579,7 +1579,7 @@ func (tmdb *TicketDB) rescanTicketDB() error { var freshTms TicketMaps freshTms.ticketMap = make([]SStxMemMap, BucketsSize, BucketsSize) - freshTms.spentTicketMap = make(map[int32]SStxMemMap) + freshTms.spentTicketMap = make(map[int64]SStxMemMap) freshTms.missedTicketMap = make(SStxMemMap) freshTms.revokedTicketMap = make(SStxMemMap) diff --git a/blockchain/stake/ticketdb_test.go b/blockchain/stake/ticketdb_test.go index ce12e4a5..44eeb273 100644 --- a/blockchain/stake/ticketdb_test.go +++ b/blockchain/stake/ticketdb_test.go @@ -60,7 +60,7 @@ func hashInSlice(h *chainhash.Hash, list []*chainhash.Hash) bool { func TestTicketDB(t *testing.T) { // Declare some useful variables - testBCHeight := int32(168) + testBCHeight := int64(168) // Set up a DB database, err := database.CreateDB("leveldb", "ticketdb_test") @@ -83,7 +83,7 @@ func TestTicketDB(t *testing.T) { // Create decoder from the buffer and a map to store the data bcDecoder := gob.NewDecoder(bcBuf) - blockchain := make(map[int32][]byte) + blockchain := make(map[int64][]byte) // Decode the blockchain into the map if err := bcDecoder.Decode(&blockchain); err != nil { @@ -94,7 +94,7 @@ func TestTicketDB(t *testing.T) { var ticketsToSpendIn167 []chainhash.Hash var sortedTickets167 []*stake.TicketData - for i := int32(0); i <= testBCHeight; i++ { + for i := int64(0); i <= testBCHeight; i++ { block, err := dcrutil.NewBlockFromBytes(blockchain[i]) if err != nil { t.Errorf("block deserialization error on block %v", i) diff --git a/blockchain/subsidy.go b/blockchain/subsidy.go index db5d7219..4a899b9a 100644 --- a/blockchain/subsidy.go +++ b/blockchain/subsidy.go @@ -26,7 +26,7 @@ import ( // 2 subsidy /= DivSubsidy // // Safe for concurrent access. -func calcBlockSubsidy(height int32, params *chaincfg.Params) int64 { +func calcBlockSubsidy(height int64, params *chaincfg.Params) int64 { // Block height 1 subsidy is 'special' and used to // distribute initial tokens, if any. if height == 1 { @@ -42,7 +42,7 @@ func calcBlockSubsidy(height int32, params *chaincfg.Params) int64 { // use is storing the total subsidy in a block node and do the // multiplication and division when needed when adding a block. if iterations > 0 { - for i := int32(0); i < iterations; i++ { + for i := int64(0); i < iterations; i++ { subsidy *= params.MulSubsidy subsidy /= params.DivSubsidy } @@ -53,7 +53,7 @@ func calcBlockSubsidy(height int32, params *chaincfg.Params) int64 { // CalcBlockWorkSubsidy calculates the proof of work subsidy for a block as a // proportion of the total subsidy. -func CalcBlockWorkSubsidy(height int32, voters uint16, +func CalcBlockWorkSubsidy(height int64, voters uint16, params *chaincfg.Params) int64 { subsidy := calcBlockSubsidy(height, params) proportionWork := int64(params.WorkRewardProportion) @@ -84,7 +84,7 @@ func CalcBlockWorkSubsidy(height int32, voters uint16, // of its input SStx. // // Safe for concurrent access. -func CalcStakeVoteSubsidy(height int32, params *chaincfg.Params) int64 { +func CalcStakeVoteSubsidy(height int64, params *chaincfg.Params) int64 { // Calculate the actual reward for this block, then further reduce reward // proportional to StakeRewardProportion. // Note that voters/potential voters is 1, so that vote reward is calculated @@ -102,13 +102,13 @@ func CalcStakeVoteSubsidy(height int32, params *chaincfg.Params) int64 { // coinbase. // // Safe for concurrent access. -func CalcBlockTaxSubsidy(height int32, voters uint16, +func CalcBlockTaxSubsidy(height int64, voters uint16, params *chaincfg.Params) int64 { if params.BlockTaxProportion == 0 { return 0 } - subsidy := calcBlockSubsidy(int32(height), params) + subsidy := calcBlockSubsidy(int64(height), params) proportionTax := int64(params.BlockTaxProportion) proportions := int64(params.TotalSubsidyProportions()) subsidy *= proportionTax @@ -265,7 +265,7 @@ func CoinbasePaysTax(tx *dcrutil.Tx, height uint32, voters uint16, // Get the amount of subsidy that should have been paid out to // the organization, then check it. - orgSubsidy := CalcBlockTaxSubsidy(int32(height), voters, params) + orgSubsidy := CalcBlockTaxSubsidy(int64(height), voters, params) amountFound := tx.MsgTx().TxOut[0].Value if orgSubsidy != amountFound { errStr := fmt.Sprintf("amount in output 0 has non matching org "+ diff --git a/blockchain/subsidy_test.go b/blockchain/subsidy_test.go index f8fc1e66..02c85f91 100644 --- a/blockchain/subsidy_test.go +++ b/blockchain/subsidy_test.go @@ -15,7 +15,7 @@ import ( func TestBlockSubsidy(t *testing.T) { mainnet := &chaincfg.MainNetParams totalSubsidy := mainnet.BlockOneSubsidy() - for i := int32(0); ; i++ { + for i := int64(0); ; i++ { // Genesis block or first block. if i == 0 || i == 1 { continue @@ -39,12 +39,12 @@ func TestBlockSubsidy(t *testing.T) { if (work + stake + tax) == 0 { break } - totalSubsidy += ((work + stake + tax) * int64(numBlocks)) + totalSubsidy += ((work + stake + tax) * numBlocks) // First reduction internal, subtract the stake subsidy for // blocks before the staking system is enabled. if i == mainnet.ReductionInterval { - totalSubsidy -= stake * int64(mainnet.StakeValidationHeight-2) + totalSubsidy -= stake * (mainnet.StakeValidationHeight - 2) } } } diff --git a/blockchain/ticketlookup.go b/blockchain/ticketlookup.go index 548f4a63..8f17d9e3 100644 --- a/blockchain/ticketlookup.go +++ b/blockchain/ticketlookup.go @@ -143,7 +143,7 @@ func (b *BlockChain) connectTickets(tixStore TicketStore, revocations := node.header.Revocations - tM := int32(b.chainParams.TicketMaturity) + tM := int64(b.chainParams.TicketMaturity) // Skip a number of validation steps before we requiring chain // voting. @@ -337,8 +337,8 @@ func (b *BlockChain) connectTickets(tixStore TicketStore, tpdBucketMap[tpd.td.Prefix] = append(data, tpd) } } - toExpireHeight := node.height - int32(b.chainParams.TicketExpiry) - if !(toExpireHeight < int32(b.chainParams.StakeEnabledHeight)) { + toExpireHeight := node.height - int64(b.chainParams.TicketExpiry) + if !(toExpireHeight < int64(b.chainParams.StakeEnabledHeight)) { for i := 0; i < stake.BucketsSize; i++ { // Generate the live ticket bucket. ltb, err := b.GenerateLiveTicketBucket(tixStore, @@ -476,7 +476,7 @@ func (b *BlockChain) disconnectTickets(tixStore TicketStore, node *blockNode, block *dcrutil.Block) error { - tM := int32(b.chainParams.TicketMaturity) + tM := int64(b.chainParams.TicketMaturity) height := node.height // Nothing to do if tickets haven't yet possibly matured. diff --git a/blockchain/txlookup.go b/blockchain/txlookup.go index e6176ab5..56ef2342 100644 --- a/blockchain/txlookup.go +++ b/blockchain/txlookup.go @@ -49,7 +49,7 @@ const ViewpointPrevInvalidRegular = int8(4) type TxData struct { Tx *dcrutil.Tx Hash *chainhash.Hash - BlockHeight int32 + BlockHeight int64 BlockIndex uint32 Spent []bool Err error @@ -199,7 +199,7 @@ func disconnectTransactions(txStore TxStore, block *dcrutil.Block, parent *dcrut // sides of a fork would otherwise not be updated. if txD, exists := txStore[*tx.Sha()]; exists { txD.Tx = nil - txD.BlockHeight = int32(wire.NullBlockHeight) + txD.BlockHeight = int64(wire.NullBlockHeight) txD.BlockIndex = wire.NullBlockIndex txD.Spent = nil txD.Err = database.ErrTxShaMissing @@ -244,7 +244,7 @@ func disconnectTransactions(txStore TxStore, block *dcrutil.Block, parent *dcrut // sides of a fork would otherwise not be updated. if txD, exists := txStore[*tx.Sha()]; exists { txD.Tx = nil - txD.BlockHeight = int32(wire.NullBlockHeight) + txD.BlockHeight = int64(wire.NullBlockHeight) txD.BlockIndex = wire.NullBlockIndex txD.Spent = nil txD.Err = database.ErrTxShaMissing diff --git a/blockchain/validate.go b/blockchain/validate.go index 2cdfe840..d6b0dc4d 100644 --- a/blockchain/validate.go +++ b/blockchain/validate.go @@ -657,7 +657,7 @@ func checkBlockSanity(block *dcrutil.Block, timeSource MedianTimeSource, // Blocks before stake validation height may only have 0x0001 // as their VoteBits in the header. - if int32(header.Height) < chainParams.StakeValidationHeight { + if int64(header.Height) < chainParams.StakeValidationHeight { if header.VoteBits != earlyVoteBitsValue { str := fmt.Sprintf("pre stake validation height block %v "+ "contained an invalid votebits value (expected %v, "+ @@ -926,7 +926,7 @@ func (b *BlockChain) checkDupTxs(node *blockNode, parentNode *blockNode, // seems unlikely that it will have stake errors (because the miner is then just // wasting hash power). func (b *BlockChain) CheckBlockStakeSanity(tixStore TicketStore, - stakeValidationHeight int32, node *blockNode, block *dcrutil.Block, + stakeValidationHeight int64, node *blockNode, block *dcrutil.Block, parent *dcrutil.Block, chainParams *chaincfg.Params) error { // Setup variables. @@ -1344,18 +1344,18 @@ func (b *BlockChain) CheckBlockStakeSanity(tixStore TicketStore, // amount, and verifying the signatures to prove the spender was the owner of // the decred and therefore allowed to spend them. As it checks the inputs, // it also calculates the total fees for the transaction and returns that value. -func CheckTransactionInputs(tx *dcrutil.Tx, txHeight int32, txStore TxStore, +func CheckTransactionInputs(tx *dcrutil.Tx, txHeight int64, txStore TxStore, checkFraudProof bool, chainParams *chaincfg.Params) (int64, error) { // Expired transactions are not allowed. if tx.MsgTx().Expiry != wire.NoExpiryValue { - if txHeight >= int32(tx.MsgTx().Expiry) { + if txHeight >= int64(tx.MsgTx().Expiry) { errStr := fmt.Sprintf("Transaction indicated an expiry of %v"+ " while the current height is %v", tx.MsgTx().Expiry, txHeight) return 0, ruleError(ErrExpiredTx, errStr) } } - ticketMaturity := int32(chainParams.TicketMaturity) + ticketMaturity := int64(chainParams.TicketMaturity) stakeEnabledHeight := chainParams.StakeEnabledHeight txHash := tx.Sha() var totalAtomIn int64 @@ -1483,7 +1483,7 @@ func CheckTransactionInputs(tx *dcrutil.Tx, txHeight int32, txStore TxStore, return 0, ruleError(ErrUnparseableSSGen, errStr) } - stakeVoteSubsidy := CalcStakeVoteSubsidy(int32(heightVotingOn), + stakeVoteSubsidy := CalcStakeVoteSubsidy(int64(heightVotingOn), chainParams) // AmountIn for the input should be equal to the stake subsidy. @@ -1744,7 +1744,7 @@ func CheckTransactionInputs(tx *dcrutil.Tx, txHeight int32, txStore TxStore, if isSSGen && idx == 0 { // However, do add the reward amount. _, heightVotingOn, _ := stake.GetSSGenBlockVotedOn(tx) - stakeVoteSubsidy := CalcStakeVoteSubsidy(int32(heightVotingOn), + stakeVoteSubsidy := CalcStakeVoteSubsidy(int64(heightVotingOn), chainParams) totalAtomIn += stakeVoteSubsidy continue @@ -1778,7 +1778,7 @@ func CheckTransactionInputs(tx *dcrutil.Tx, txHeight int32, txStore TxStore, return 0, ruleError(ErrFraudAmountIn, str) } - if int32(txIn.BlockHeight) != originTx.BlockHeight { + if int64(txIn.BlockHeight) != originTx.BlockHeight { str := fmt.Sprintf("bad fraud check block height (expected %v, "+ "given %v) for txIn %v", originTx.BlockHeight, txIn.BlockHeight, idx) @@ -1795,7 +1795,7 @@ func CheckTransactionInputs(tx *dcrutil.Tx, txHeight int32, txStore TxStore, // Ensure the transaction is not spending coins which have not // yet reached the required coinbase maturity. - coinbaseMaturity := int32(chainParams.CoinbaseMaturity) + coinbaseMaturity := int64(chainParams.CoinbaseMaturity) if IsCoinBase(originTx.Tx) { originHeight := originTx.BlockHeight blocksSincePrev := txHeight - originHeight @@ -1889,7 +1889,7 @@ func CheckTransactionInputs(tx *dcrutil.Tx, txHeight int32, txStore TxStore, originHeight := originTx.BlockHeight blocksSincePrev := txHeight - originHeight - if blocksSincePrev < int32(chainParams.SStxChangeMaturity) { + if blocksSincePrev < int64(chainParams.SStxChangeMaturity) { str := fmt.Sprintf("tried to spend OP_SSGEN or "+ "OP_SSRTX output from tx %v from height %v at "+ "height %v before required maturity "+ @@ -1904,7 +1904,7 @@ func CheckTransactionInputs(tx *dcrutil.Tx, txHeight int32, txStore TxStore, if scriptClass == txscript.StakeSubChangeTy { originHeight := originTx.BlockHeight blocksSincePrev := txHeight - originHeight - if blocksSincePrev < int32(chainParams.SStxChangeMaturity) { + if blocksSincePrev < int64(chainParams.SStxChangeMaturity) { str := fmt.Sprintf("tried to spend SStx change "+ "output from tx %v from height %v at "+ "height %v before required maturity "+ @@ -2046,7 +2046,7 @@ func checkP2SHNumSigOps(txs []*dcrutil.Tx, txInputStore TxStore, // checkStakeBaseAmounts calculates the total amount given as subsidy from // single stakebase transactions (votes) within a block. This function skips a // ton of checks already performed by CheckTransactionInputs. -func checkStakeBaseAmounts(height int32, params *chaincfg.Params, +func checkStakeBaseAmounts(height int64, params *chaincfg.Params, txs []*dcrutil.Tx, txStore TxStore) error { for _, tx := range txs { if is, _ := stake.IsSSGen(tx); is { @@ -2121,7 +2121,7 @@ func getStakeBaseAmounts(txs []*dcrutil.Tx, txStore TxStore) (int64, error) { // getStakeTreeFees determines the amount of fees for in the stake tx tree // of some node given a transaction store. -func getStakeTreeFees(height int32, params *chaincfg.Params, +func getStakeTreeFees(height int64, params *chaincfg.Params, txs []*dcrutil.Tx, txStore TxStore) (dcrutil.Amount, error) { totalInputs := int64(0) totalOutputs := int64(0) diff --git a/blockchain/validate_test.go b/blockchain/validate_test.go index 09740147..b51db5ca 100644 --- a/blockchain/validate_test.go +++ b/blockchain/validate_test.go @@ -91,7 +91,7 @@ func TestBlockValidationRules(t *testing.T) { // Create decoder from the buffer and a map to store the data bcDecoder := gob.NewDecoder(bcBuf) - blockChain := make(map[int32][]byte) + blockChain := make(map[int64][]byte) // Decode the blockchain into the map if err := bcDecoder.Decode(&blockChain); err != nil { @@ -100,7 +100,7 @@ func TestBlockValidationRules(t *testing.T) { // Insert blocks 1 to 142 and perform various test. Block 1 has // special properties, so make sure those validate correctly first. - block1Bytes := blockChain[int32(1)] + block1Bytes := blockChain[int64(1)] timeSource := blockchain.NewMedianTime() // ---------------------------------------------------------------------------- @@ -118,7 +118,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(noCoinbaseOuts1) b1test := dcrutil.NewBlock(noCoinbaseOuts1) - b1test.SetHeight(int32(1)) + b1test.SetHeight(int64(1)) err = blockchain.CheckWorklessBlockSanity(b1test, timeSource, simNetParams) if err != nil { @@ -141,7 +141,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(noCoinbaseOuts1) b1test = dcrutil.NewBlock(noCoinbaseOuts1) - b1test.SetHeight(int32(1)) + b1test.SetHeight(int64(1)) err = blockchain.CheckWorklessBlockSanity(b1test, timeSource, simNetParams) if err != nil { @@ -164,7 +164,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(noCoinbaseOuts1) b1test = dcrutil.NewBlock(noCoinbaseOuts1) - b1test.SetHeight(int32(1)) + b1test.SetHeight(int64(1)) err = blockchain.CheckWorklessBlockSanity(b1test, timeSource, simNetParams) if err != nil { @@ -182,11 +182,11 @@ func TestBlockValidationRules(t *testing.T) { // Add the rest of the blocks up to the stake early test block. stakeEarlyTest := 142 for i := 1; i < stakeEarlyTest; i++ { - bl, err := dcrutil.NewBlockFromBytes(blockChain[int32(i)]) + bl, err := dcrutil.NewBlockFromBytes(blockChain[int64(i)]) if err != nil { t.Errorf("NewBlockFromBytes error: %v", err.Error()) } - bl.SetHeight(int32(i)) + bl.SetHeight(int64(i)) _, _, err = chain.ProcessBlock(bl, timeSource, blockchain.BFNone) if err != nil { @@ -197,7 +197,7 @@ func TestBlockValidationRules(t *testing.T) { // ---------------------------------------------------------------------------- // ErrInvalidEarlyStakeTx // There are multiple paths to this error, but here we try an early SSGen. - block142Bytes := blockChain[int32(stakeEarlyTest)] + block142Bytes := blockChain[int64(stakeEarlyTest)] earlySSGen142 := new(wire.MsgBlock) earlySSGen142.FromBytes(block142Bytes) @@ -217,7 +217,7 @@ func TestBlockValidationRules(t *testing.T) { earlySSGen142.AddSTransaction(mtxFromB) recalculateMsgBlockMerkleRootsSize(earlySSGen142) b142test := dcrutil.NewBlock(earlySSGen142) - b142test.SetHeight(int32(stakeEarlyTest)) + b142test.SetHeight(int64(stakeEarlyTest)) err = blockchain.CheckWorklessBlockSanity(b142test, timeSource, simNetParams) if err == nil { @@ -238,7 +238,7 @@ func TestBlockValidationRules(t *testing.T) { earlyBadVoteBits42.FromBytes(block142Bytes) earlyBadVoteBits42.Header.VoteBits ^= 0x80 b142test = dcrutil.NewBlock(earlyBadVoteBits42) - b142test.SetHeight(int32(stakeEarlyTest)) + b142test.SetHeight(int64(stakeEarlyTest)) err = blockchain.CheckWorklessBlockSanity(b142test, timeSource, simNetParams) if err == nil || err.(blockchain.RuleError).GetCode() != @@ -259,11 +259,11 @@ func TestBlockValidationRules(t *testing.T) { testsIdx2 := 154 testsIdx3 := 166 for i := stakeEarlyTest; i < testsIdx1; i++ { - bl, err := dcrutil.NewBlockFromBytes(blockChain[int32(i)]) + bl, err := dcrutil.NewBlockFromBytes(blockChain[int64(i)]) if err != nil { t.Errorf("NewBlockFromBytes error: %v", err.Error()) } - bl.SetHeight(int32(i)) + bl.SetHeight(int64(i)) _, _, err = chain.ProcessBlock(bl, timeSource, blockchain.BFNone) if err != nil { @@ -272,16 +272,16 @@ func TestBlockValidationRules(t *testing.T) { } // Make sure the last block validates. - block153, err := dcrutil.NewBlockFromBytes(blockChain[int32(testsIdx1)]) + block153, err := dcrutil.NewBlockFromBytes(blockChain[int64(testsIdx1)]) if err != nil { t.Errorf("NewBlockFromBytes error: %v", err.Error()) } - block153.SetHeight(int32(testsIdx1)) + block153.SetHeight(int64(testsIdx1)) err = chain.CheckConnectBlock(block153) if err != nil { t.Errorf("CheckConnectBlock error: %v", err.Error()) } - block153Bytes := blockChain[int32(testsIdx1)] + block153Bytes := blockChain[int64(testsIdx1)] // ---------------------------------------------------------------------------- // ErrBadMerkleRoot 1 @@ -290,7 +290,7 @@ func TestBlockValidationRules(t *testing.T) { badMerkleRoot153.FromBytes(block153Bytes) badMerkleRoot153.Header.MerkleRoot[0] ^= 0x01 b153test := dcrutil.NewBlock(badMerkleRoot153) - b153test.SetHeight(int32(testsIdx1)) + b153test.SetHeight(int64(testsIdx1)) err = blockchain.CheckWorklessBlockSanity(b153test, timeSource, simNetParams) if err == nil || err.(blockchain.RuleError).GetCode() != @@ -313,7 +313,7 @@ func TestBlockValidationRules(t *testing.T) { badMerkleRoot153.FromBytes(block153Bytes) badMerkleRoot153.Header.StakeRoot[0] ^= 0x01 b153test = dcrutil.NewBlock(badMerkleRoot153) - b153test.SetHeight(int32(testsIdx1)) + b153test.SetHeight(int64(testsIdx1)) err = blockchain.CheckWorklessBlockSanity(b153test, timeSource, simNetParams) if err == nil || err.(blockchain.RuleError).GetCode() != @@ -335,7 +335,7 @@ func TestBlockValidationRules(t *testing.T) { badDifficulty153.FromBytes(block153Bytes) badDifficulty153.Header.Bits = 0x207ffffe b153test = dcrutil.NewBlock(badDifficulty153) - b153test.SetHeight(int32(testsIdx1)) + b153test.SetHeight(int64(testsIdx1)) _, _, err = chain.ProcessBlock(b153test, timeSource, blockchain.BFNone) if err == nil || err.(blockchain.RuleError).GetCode() != @@ -350,7 +350,7 @@ func TestBlockValidationRules(t *testing.T) { badBlockSize153.FromBytes(block153Bytes) badBlockSize153.Header.Size = 0x20ffff71 b153test = dcrutil.NewBlock(badBlockSize153) - b153test.SetHeight(int32(testsIdx1)) + b153test.SetHeight(int64(testsIdx1)) _, _, err = chain.ProcessBlock(b153test, timeSource, blockchain.BFNoPoWCheck) if err == nil || err.(blockchain.RuleError).GetCode() != @@ -365,7 +365,7 @@ func TestBlockValidationRules(t *testing.T) { badHash153.FromBytes(block153Bytes) badHash153.Header.Size = 0x20ffff70 b153test = dcrutil.NewBlock(badHash153) - b153test.SetHeight(int32(testsIdx1)) + b153test.SetHeight(int64(testsIdx1)) _, _, err = chain.ProcessBlock(b153test, timeSource, blockchain.BFNone) if err == nil || err.(blockchain.RuleError).GetCode() != @@ -380,7 +380,7 @@ func TestBlockValidationRules(t *testing.T) { missingParent153.FromBytes(block153Bytes) missingParent153.Header.PrevBlock[8] ^= 0x01 b153test = dcrutil.NewBlock(missingParent153) - b153test.SetHeight(int32(testsIdx1)) + b153test.SetHeight(int64(testsIdx1)) err = blockchain.CheckWorklessBlockSanity(b153test, timeSource, simNetParams) if err != nil { @@ -401,7 +401,7 @@ func TestBlockValidationRules(t *testing.T) { badSubsidy153.Transactions[0].TxOut[2].Value++ recalculateMsgBlockMerkleRootsSize(badSubsidy153) b153test = dcrutil.NewBlock(badSubsidy153) - b153test.SetHeight(int32(testsIdx1)) + b153test.SetHeight(int64(testsIdx1)) err = blockchain.CheckWorklessBlockSanity(b153test, timeSource, simNetParams) if err != nil { @@ -424,7 +424,7 @@ func TestBlockValidationRules(t *testing.T) { badCBOutpoint153.Transactions[0].TxIn[0].PreviousOutPoint.Hash[0] ^= 0x01 recalculateMsgBlockMerkleRootsSize(badCBOutpoint153) b153test = dcrutil.NewBlock(badCBOutpoint153) - b153test.SetHeight(int32(testsIdx1)) + b153test.SetHeight(int64(testsIdx1)) err = blockchain.CheckWorklessBlockSanity(b153test, timeSource, simNetParams) if err == nil || err.(blockchain.RuleError).GetCode() != @@ -445,7 +445,7 @@ func TestBlockValidationRules(t *testing.T) { badCBFraudProof153.Transactions[0].TxIn[0].BlockHeight = 0x12345678 recalculateMsgBlockMerkleRootsSize(badCBFraudProof153) b153test = dcrutil.NewBlock(badCBFraudProof153) - b153test.SetHeight(int32(testsIdx1)) + b153test.SetHeight(int64(testsIdx1)) err = blockchain.CheckWorklessBlockSanity(b153test, timeSource, simNetParams) if err == nil || err.(blockchain.RuleError).GetCode() != @@ -467,7 +467,7 @@ func TestBlockValidationRules(t *testing.T) { badCBAmountIn153.Transactions[0].TxIn[0].ValueIn = 0x1234567890123456 recalculateMsgBlockMerkleRootsSize(badCBAmountIn153) b153test = dcrutil.NewBlock(badCBAmountIn153) - b153test.SetHeight(int32(testsIdx1)) + b153test.SetHeight(int64(testsIdx1)) err = blockchain.CheckWorklessBlockSanity(b153test, timeSource, simNetParams) if err != nil { @@ -489,7 +489,7 @@ func TestBlockValidationRules(t *testing.T) { badSBAmountIn153.STransactions[0].TxIn[0].ValueIn = 0x1234567890123456 recalculateMsgBlockMerkleRootsSize(badSBAmountIn153) b153test = dcrutil.NewBlock(badSBAmountIn153) - b153test.SetHeight(int32(testsIdx1)) + b153test.SetHeight(int64(testsIdx1)) err = blockchain.CheckWorklessBlockSanity(b153test, timeSource, simNetParams) if err != nil { @@ -516,7 +516,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(badStakebaseOutpoint153) badStakebaseOutpoint153.Header.Voters-- b153test = dcrutil.NewBlock(badStakebaseOutpoint153) - b153test.SetHeight(int32(testsIdx1)) + b153test.SetHeight(int64(testsIdx1)) err = blockchain.CheckWorklessBlockSanity(b153test, timeSource, simNetParams) if err == nil || err.(blockchain.RuleError).GetCode() != @@ -542,7 +542,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(ssgenInRegular153) b153test = dcrutil.NewBlock(ssgenInRegular153) - b153test.SetHeight(int32(testsIdx1)) + b153test.SetHeight(int64(testsIdx1)) err = blockchain.CheckWorklessBlockSanity(b153test, timeSource, simNetParams) if err == nil || err.(blockchain.RuleError).GetCode() != @@ -566,7 +566,7 @@ func TestBlockValidationRules(t *testing.T) { badStakebaseSS recalculateMsgBlockMerkleRootsSize(badStakebaseSS153) b153test = dcrutil.NewBlock(badStakebaseSS153) - b153test.SetHeight(int32(testsIdx1)) + b153test.SetHeight(int64(testsIdx1)) err = blockchain.CheckWorklessBlockSanity(b153test, timeSource, simNetParams) if err == nil || err.(blockchain.RuleError).GetCode() != @@ -589,7 +589,7 @@ func TestBlockValidationRules(t *testing.T) { badStakebaseScr153.STransactions[0].TxIn[0].SignatureScript[0] ^= 0x01 recalculateMsgBlockMerkleRootsSize(badStakebaseScr153) b153test = dcrutil.NewBlock(badStakebaseScr153) - b153test.SetHeight(int32(testsIdx1)) + b153test.SetHeight(int64(testsIdx1)) err = blockchain.CheckWorklessBlockSanity(b153test, timeSource, simNetParams) if err == nil || err.(blockchain.RuleError).GetCode() != @@ -612,7 +612,7 @@ func TestBlockValidationRules(t *testing.T) { badSSRtxNum153.Header.Revocations = 2 b153test = dcrutil.NewBlock(badSSRtxNum153) - b153test.SetHeight(int32(testsIdx1)) + b153test.SetHeight(int64(testsIdx1)) err = blockchain.CheckWorklessBlockSanity(b153test, timeSource, simNetParams) if err != nil { @@ -639,7 +639,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(ssrtxPayeesMismatch153) b153test = dcrutil.NewBlock(ssrtxPayeesMismatch153) - b153test.SetHeight(int32(testsIdx1)) + b153test.SetHeight(int64(testsIdx1)) err = blockchain.CheckWorklessBlockSanity(b153test, timeSource, simNetParams) if err != nil { @@ -664,7 +664,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(badSSRtxPayee153) b153test = dcrutil.NewBlock(badSSRtxPayee153) - b153test.SetHeight(int32(testsIdx1)) + b153test.SetHeight(int64(testsIdx1)) err = blockchain.CheckWorklessBlockSanity(b153test, timeSource, simNetParams) if err != nil { @@ -691,7 +691,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(badSSRtxPayee153) b153test = dcrutil.NewBlock(badSSRtxPayee153) - b153test.SetHeight(int32(testsIdx1)) + b153test.SetHeight(int64(testsIdx1)) err = blockchain.CheckWorklessBlockSanity(b153test, timeSource, simNetParams) if err != nil { @@ -726,7 +726,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(badSSRtx153) b153test = dcrutil.NewBlock(badSSRtx153) - b153test.SetHeight(int32(testsIdx1)) + b153test.SetHeight(int64(testsIdx1)) err = blockchain.CheckWorklessBlockSanity(b153test, timeSource, simNetParams) if err != nil { @@ -747,16 +747,16 @@ func TestBlockValidationRules(t *testing.T) { block153MsgBlock := new(wire.MsgBlock) block153MsgBlock.FromBytes(block153Bytes) b153test = dcrutil.NewBlock(block153MsgBlock) - b153test.SetHeight(int32(testsIdx1)) + b153test.SetHeight(int64(testsIdx1)) _, _, err = chain.ProcessBlock(b153test, timeSource, blockchain.BFNone) if err != nil { t.Errorf("Got unexpected error processing block 153 %v", err) } - block154Bytes := blockChain[int32(testsIdx2)] + block154Bytes := blockChain[int64(testsIdx2)] block154MsgBlock := new(wire.MsgBlock) block154MsgBlock.FromBytes(block154Bytes) b154test := dcrutil.NewBlock(block154MsgBlock) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) // The incoming block should pass fine. err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) @@ -777,7 +777,7 @@ func TestBlockValidationRules(t *testing.T) { notEnoughStake154.AddSTransaction(mtxFromB) recalculateMsgBlockMerkleRootsSize(notEnoughStake154) b154test = dcrutil.NewBlock(notEnoughStake154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) // This fails both checks. err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) @@ -800,7 +800,7 @@ func TestBlockValidationRules(t *testing.T) { badFreshStake154.Header.FreshStake++ recalculateMsgBlockMerkleRootsSize(badFreshStake154) b154test = dcrutil.NewBlock(badFreshStake154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) // This passes. err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) @@ -829,7 +829,7 @@ func TestBlockValidationRules(t *testing.T) { notEnoughVotes154.STransactions = notEnoughVotes154.STransactions[0:2] recalculateMsgBlockMerkleRootsSize(notEnoughVotes154) b154test = dcrutil.NewBlock(notEnoughVotes154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -868,7 +868,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(tooManyVotes154) b154test = dcrutil.NewBlock(tooManyVotes154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) // Fails tax amount test. err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) @@ -892,7 +892,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(nonChosenTicket154) b154test = dcrutil.NewBlock(nonChosenTicket154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -919,7 +919,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(wrongBlockVote154) b154test = dcrutil.NewBlock(wrongBlockVote154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -945,7 +945,7 @@ func TestBlockValidationRules(t *testing.T) { sstxsIn154...) recalculateMsgBlockMerkleRootsSize(votesMismatch154) b154test = dcrutil.NewBlock(votesMismatch154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -968,7 +968,7 @@ func TestBlockValidationRules(t *testing.T) { badVoteBit154.FromBytes(block154Bytes) badVoteBit154.Header.VoteBits &= 0xFFFE // Zero critical voteBit b154test = dcrutil.NewBlock(badVoteBit154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -998,7 +998,7 @@ func TestBlockValidationRules(t *testing.T) { } recalculateMsgBlockMerkleRootsSize(badVoteBit154) b154test = dcrutil.NewBlock(badVoteBit154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1028,7 +1028,7 @@ func TestBlockValidationRules(t *testing.T) { } recalculateMsgBlockMerkleRootsSize(badVoteBit154) b154test = dcrutil.NewBlock(badVoteBit154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1058,7 +1058,7 @@ func TestBlockValidationRules(t *testing.T) { } recalculateMsgBlockMerkleRootsSize(badVoteBit154) b154test = dcrutil.NewBlock(badVoteBit154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1093,7 +1093,7 @@ func TestBlockValidationRules(t *testing.T) { } recalculateMsgBlockMerkleRootsSize(badVoteBit154) b154test = dcrutil.NewBlock(badVoteBit154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1128,7 +1128,7 @@ func TestBlockValidationRules(t *testing.T) { } recalculateMsgBlockMerkleRootsSize(badVoteBit154) b154test = dcrutil.NewBlock(badVoteBit154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1163,7 +1163,7 @@ func TestBlockValidationRules(t *testing.T) { } recalculateMsgBlockMerkleRootsSize(badVoteBit154) b154test = dcrutil.NewBlock(badVoteBit154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1190,7 +1190,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(badSStxCommit154) b154test = dcrutil.NewBlock(badSStxCommit154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1224,7 +1224,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(badSSGenPayee154) b154test = dcrutil.NewBlock(badSSGenPayee154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1249,7 +1249,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(badSSGenPayee154) b154test = dcrutil.NewBlock(badSSGenPayee154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1311,7 +1311,7 @@ func TestBlockValidationRules(t *testing.T) { spendTaggedIn154.Transactions[11] = mtxFromB recalculateMsgBlockMerkleRootsSize(spendTaggedIn154) b154test = dcrutil.NewBlock(spendTaggedIn154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1340,7 +1340,7 @@ func TestBlockValidationRules(t *testing.T) { spendTaggedOut154.Transactions[11] = mtxFromB recalculateMsgBlockMerkleRootsSize(spendTaggedOut154) b154test = dcrutil.NewBlock(spendTaggedOut154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1362,7 +1362,7 @@ func TestBlockValidationRules(t *testing.T) { badFinalState154.FromBytes(block154Bytes) badFinalState154.Header.FinalState[0] ^= 0x01 b154test = dcrutil.NewBlock(badFinalState154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1384,7 +1384,7 @@ func TestBlockValidationRules(t *testing.T) { badPoolSize154.FromBytes(block154Bytes) badPoolSize154.Header.PoolSize++ b154test = dcrutil.NewBlock(badPoolSize154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1416,7 +1416,7 @@ func TestBlockValidationRules(t *testing.T) { errTxTreeIn154.Transactions[11] = mtxFromB recalculateMsgBlockMerkleRootsSize(errTxTreeIn154) b154test = dcrutil.NewBlock(errTxTreeIn154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1444,7 +1444,7 @@ func TestBlockValidationRules(t *testing.T) { badBlockHeight154.FromBytes(block154Bytes) badBlockHeight154.Header.Height++ b154test = dcrutil.NewBlock(badBlockHeight154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) // Throws ProcessBlock error through checkBlockContext. _, _, err = chain.ProcessBlock(b154test, timeSource, blockchain.BFNoPoWCheck) @@ -1463,7 +1463,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(taxMissing154) b154test = dcrutil.NewBlock(taxMissing154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err == nil || err.(blockchain.RuleError).GetCode() != @@ -1485,7 +1485,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(taxMissing154) b154test = dcrutil.NewBlock(taxMissing154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err == nil || err.(blockchain.RuleError).GetCode() != @@ -1507,7 +1507,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(taxMissing154) b154test = dcrutil.NewBlock(taxMissing154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err == nil || err.(blockchain.RuleError).GetCode() != @@ -1532,7 +1532,7 @@ func TestBlockValidationRules(t *testing.T) { expiredTx154.AddTransaction(mtxFromB) recalculateMsgBlockMerkleRootsSize(expiredTx154) b154test = dcrutil.NewBlock(expiredTx154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1559,7 +1559,7 @@ func TestBlockValidationRules(t *testing.T) { badValueIn154.Transactions[11] = mtxFromB recalculateMsgBlockMerkleRootsSize(badValueIn154) b154test = dcrutil.NewBlock(badValueIn154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1586,7 +1586,7 @@ func TestBlockValidationRules(t *testing.T) { badHeightProof154.Transactions[11] = mtxFromB recalculateMsgBlockMerkleRootsSize(badHeightProof154) b154test = dcrutil.NewBlock(badHeightProof154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1613,7 +1613,7 @@ func TestBlockValidationRules(t *testing.T) { badIndexProof154.Transactions[11] = mtxFromB recalculateMsgBlockMerkleRootsSize(badIndexProof154) b154test = dcrutil.NewBlock(badIndexProof154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1640,7 +1640,7 @@ func TestBlockValidationRules(t *testing.T) { badScrVal154.Transactions[11] = mtxFromB recalculateMsgBlockMerkleRootsSize(badScrVal154) b154test = dcrutil.NewBlock(badScrVal154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1663,7 +1663,7 @@ func TestBlockValidationRules(t *testing.T) { badScrValS154.STransactions[5].TxIn[0].SignatureScript[6] ^= 0x01 recalculateMsgBlockMerkleRootsSize(badScrValS154) b154test = dcrutil.NewBlock(badScrValS154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1693,7 +1693,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(invalMissingInsS154) b154test = dcrutil.NewBlock(invalMissingInsS154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1720,7 +1720,7 @@ func TestBlockValidationRules(t *testing.T) { malformedScr154.Transactions[11] = mtxFromB recalculateMsgBlockMerkleRootsSize(malformedScr154) b154test = dcrutil.NewBlock(malformedScr154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1759,7 +1759,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(spendZeroValueIn154) b154test = dcrutil.NewBlock(spendZeroValueIn154) - b154test.SetHeight(int32(testsIdx2)) + b154test.SetHeight(int64(testsIdx2)) err = blockchain.CheckWorklessBlockSanity(b154test, timeSource, simNetParams) if err != nil { @@ -1781,11 +1781,11 @@ func TestBlockValidationRules(t *testing.T) { // Load up to block 166. 165 invalidates its previous tx tree, making // it good for testing. for i := testsIdx2; i < testsIdx3; i++ { - bl, err := dcrutil.NewBlockFromBytes(blockChain[int32(i)]) + bl, err := dcrutil.NewBlockFromBytes(blockChain[int64(i)]) if err != nil { t.Errorf("NewBlockFromBytes error: %v", err.Error()) } - bl.SetHeight(int32(i)) + bl.SetHeight(int64(i)) // Double check and ensure there's no cross tree spending in // block 164. @@ -1809,7 +1809,7 @@ func TestBlockValidationRules(t *testing.T) { t.Errorf("ProcessBlock error: %v", err.Error()) } } - block166Bytes := blockChain[int32(testsIdx3)] + block166Bytes := blockChain[int64(testsIdx3)] // ---------------------------------------------------------------------------- // Attempt to spend from TxTreeRegular of block 164, which should never @@ -1826,7 +1826,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(spendInvalid166) b166test := dcrutil.NewBlock(spendInvalid166) - b166test.SetHeight(int32(testsIdx3)) + b166test.SetHeight(int64(testsIdx3)) err = blockchain.CheckWorklessBlockSanity(b166test, timeSource, simNetParams) if err != nil { @@ -1874,7 +1874,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(sstxSpendInvalid166) b166test = dcrutil.NewBlock(sstxSpendInvalid166) - b166test.SetHeight(int32(testsIdx3)) + b166test.SetHeight(int64(testsIdx3)) err = blockchain.CheckWorklessBlockSanity(b166test, timeSource, simNetParams) if err != nil { @@ -1917,7 +1917,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(sstxSpend2Invalid166) b166test = dcrutil.NewBlock(sstxSpend2Invalid166) - b166test.SetHeight(int32(testsIdx3)) + b166test.SetHeight(int64(testsIdx3)) err = blockchain.CheckWorklessBlockSanity(b166test, timeSource, simNetParams) if err != nil { @@ -1950,7 +1950,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(sstxSpend3Invalid166) b166test = dcrutil.NewBlock(sstxSpend3Invalid166) - b166test.SetHeight(int32(testsIdx3)) + b166test.SetHeight(int64(testsIdx3)) err = blockchain.CheckWorklessBlockSanity(b166test, timeSource, simNetParams) if err != nil { @@ -1976,7 +1976,7 @@ func TestBlockValidationRules(t *testing.T) { recalculateMsgBlockMerkleRootsSize(regTxSpendStakeIn166) b166test = dcrutil.NewBlock(regTxSpendStakeIn166) - b166test.SetHeight(int32(testsIdx3)) + b166test.SetHeight(int64(testsIdx3)) err = blockchain.CheckWorklessBlockSanity(b166test, timeSource, simNetParams) if err != nil { diff --git a/blockmanager.go b/blockmanager.go index 77d4a8dd..85fd1ae1 100644 --- a/blockmanager.go +++ b/blockmanager.go @@ -415,7 +415,7 @@ type setParentTemplateResponse struct { // headerNode is used as a node in a list of headers that are linked together // between checkpoints. type headerNode struct { - height int32 + height int64 sha *chainhash.Hash } @@ -428,7 +428,7 @@ type headerNode struct { type chainState struct { sync.Mutex newestHash *chainhash.Hash - newestHeight int32 + newestHeight int64 nextFinalState [6]byte nextPoolSize uint32 winningTickets []chainhash.Hash @@ -442,7 +442,7 @@ type chainState struct { // chain. // // This function is safe for concurrent access. -func (c *chainState) Best() (*chainhash.Hash, int32) { +func (c *chainState) Best() (*chainhash.Hash, int64) { c.Lock() defer c.Unlock() @@ -545,7 +545,7 @@ type blockManager struct { // resetHeaderState sets the headers-first mode state to values appropriate for // syncing from a new peer. -func (b *blockManager) resetHeaderState(newestHash *chainhash.Hash, newestHeight int32) { +func (b *blockManager) resetHeaderState(newestHash *chainhash.Hash, newestHeight int64) { b.headersFirstMode = false b.headerList.Init() b.startHeader = nil @@ -564,7 +564,7 @@ func (b *blockManager) resetHeaderState(newestHash *chainhash.Hash, newestHeight // safe for concurrent access and the block manager is typically quite busy // processing block and inventory. func (b *blockManager) updateChainState(newestHash *chainhash.Hash, - newestHeight int32, + newestHeight int64, finalState [6]byte, poolSize uint32, winningTickets []chainhash.Hash, @@ -594,7 +594,7 @@ func (b *blockManager) updateChainState(newestHash *chainhash.Hash, // It returns nil when there is not one either because the height is already // later than the final checkpoint or some other reason such as disabled // checkpoints. -func (b *blockManager) findNextHeaderCheckpoint(height int32) *chaincfg.Checkpoint { +func (b *blockManager) findNextHeaderCheckpoint(height int64) *chaincfg.Checkpoint { // There is no next checkpoint if checkpoints are disabled or there are // none for this current network. if cfg.DisableCheckpoints { @@ -919,7 +919,7 @@ func (b *blockManager) current() bool { // TODO(oga) we can get chain to return the height of each block when we // parse an orphan, which would allow us to update the height of peers // from what it was at initial handshake. - if err != nil || height < b.syncPeer.lastBlock { + if err != nil || height < int64(b.syncPeer.startingHeight) { return false } @@ -1070,7 +1070,7 @@ func (b *blockManager) checkBlockForHiddenVotes(block *dcrutil.Block) { coinbase, err := createCoinbaseTx( template.block.Transactions[0].TxIn[0].SignatureScript, opReturnPkScript, - int32(template.block.Header.Height), + int64(template.block.Header.Height), cfg.miningAddrs[rand.Intn(len(cfg.miningAddrs))], uint16(votesTotal), b.server.chainParams) @@ -1235,7 +1235,7 @@ func (b *blockManager) handleBlockMsg(bmsg *blockMsg) { if !exists { winningTickets, poolSize, finalState, err := b.blockChain.GetWinningTickets(*blockSha) - if err != nil && int32(bmsg.block.MsgBlock().Header.Height) >= + if err != nil && int64(bmsg.block.MsgBlock().Header.Height) >= b.server.chainParams.StakeValidationHeight-1 { bmgrLog.Errorf("Failed to get next winning tickets: %v", err) @@ -1248,7 +1248,7 @@ func (b *blockManager) handleBlockMsg(bmsg *blockMsg) { winningTicketsNtfn := &WinningTicketsNtfnData{ *blockSha, - int32(bmsg.block.MsgBlock().Header.Height), + int64(bmsg.block.MsgBlock().Header.Height), winningTickets} lotteryData = &BlockLotteryData{ winningTicketsNtfn, @@ -1937,7 +1937,7 @@ out: if !exists { winningTickets, poolSize, finalState, err := b.blockChain.GetWinningTickets(*msg.block.Sha()) - if err != nil && int32(msg.block.MsgBlock().Header.Height) >= + if err != nil && int64(msg.block.MsgBlock().Header.Height) >= b.server.chainParams.StakeValidationHeight-1 { bmgrLog.Warnf("Stake failure in lottery tickets "+ "calculation: %v", err) @@ -1953,7 +1953,7 @@ out: lotteryData.finalState = finalState lotteryData.ntfnData = &WinningTicketsNtfnData{ *msg.block.Sha(), - int32(msg.block.MsgBlock().Header.Height), + int64(msg.block.MsgBlock().Header.Height), winningTickets} b.blockLotteryDataCache[*msg.block.Sha()] = lotteryData broadcastWinners = true @@ -2143,7 +2143,7 @@ func (b *blockManager) handleNotifyMsg(notification *blockchain.Notification) { lotteryData.ntfnData = &WinningTicketsNtfnData{ *hash, - int32(block.MsgBlock().Header.Height), + int64(block.MsgBlock().Header.Height), wt} b.blockLotteryDataCache[*hash] = lotteryData @@ -2938,9 +2938,9 @@ func setupBlockDB() (dcrdb.Db, error) { } // dumpBlockChain dumps a map of the blockchain blocks as serialized bytes. -func dumpBlockChain(height int32, db dcrdb.Db) error { - blockchain := make(map[int32][]byte) - for i := int32(0); i <= height; i++ { +func dumpBlockChain(height int64, db dcrdb.Db) error { + blockchain := make(map[int64][]byte) + for i := int64(0); i <= height; i++ { // Fetch blocks and put them in the map sha, err := db.FetchBlockShaByHeight(i) if err != nil { @@ -2993,7 +2993,7 @@ func loadBlockDB() (dcrdb.Db, error) { // connected to if needed. if height == -1 { genesis := dcrutil.NewBlock(activeNetParams.GenesisBlock) - genesis.SetHeight(int32(0)) + genesis.SetHeight(int64(0)) _, err := db.InsertBlock(genesis) if err != nil { db.Close() diff --git a/chaincfg/params.go b/chaincfg/params.go index 70e87a8b..cf7b42e7 100644 --- a/chaincfg/params.go +++ b/chaincfg/params.go @@ -57,7 +57,7 @@ var CPUMinerThreads = 1 // documentation for chain.IsCheckpointCandidate for details on the selection // criteria. type Checkpoint struct { - Height int32 + Height int64 Hash *chainhash.Hash } @@ -116,7 +116,7 @@ type Params struct { // WorkDiffWindowSize is the number of windows (intervals) used for calculation // of the exponentially weighted average. - WorkDiffWindowSize int32 + WorkDiffWindowSize int64 // WorkDiffWindows is the number of windows (intervals) used for calculation // of the exponentially weighted average. @@ -153,7 +153,7 @@ type Params struct { DivSubsidy int64 // Reduction interval in blocks. - ReductionInterval int32 + ReductionInterval int64 // WorkRewardProportion is the comparative amount of the subsidy given for // creating a block. @@ -231,7 +231,7 @@ type Params struct { // StakeDiffWindowSize is the number of blocks used for each interval in // exponentially weighted average. - StakeDiffWindowSize int32 + StakeDiffWindowSize int64 // StakeDiffWindows is the number of windows (intervals) used for calculation // of the exponentially weighted average. @@ -243,12 +243,12 @@ type Params struct { // StakeEnabledHeight is the height in which the first ticket could possibly // mature. - StakeEnabledHeight int32 + StakeEnabledHeight int64 // StakeValidationHeight is the height at which votes (SSGen) are required // to add a new block to the top of the blockchain. This height is the // first block that will be voted on, but will include in itself no votes. - StakeValidationHeight int32 + StakeValidationHeight int64 // StakeBaseSigScript is the consensus stakebase signature script for all // votes on the network. This isn't signed in any way, so without forcing diff --git a/chainindexer.go b/chainindexer.go index 155f021a..5d2726af 100644 --- a/chainindexer.go +++ b/chainindexer.go @@ -48,8 +48,8 @@ type addrIndexer struct { shutdown int32 state indexState progressLogger *blockProgressLogger - currentIndexTip int32 - chainTip int32 + currentIndexTip int64 + chainTip int64 sync.Mutex } @@ -188,7 +188,7 @@ func (a *addrIndexer) initialize() error { // passed SPK and returns a TxAddrIndex with the given data. Our "address" // index is actually a hash160 index, where in the ideal case the data push // is either the hash160 of a publicKey (P2PKH) or a Script (P2SH). -func convertToAddrIndex(scrVersion uint16, scr []byte, height int32, +func convertToAddrIndex(scrVersion uint16, scr []byte, height int64, locInBlock *wire.TxLoc) ([]*database.TxAddrIndex, error) { var tais []*database.TxAddrIndex diff --git a/cmd/dropafter/dropafter.go b/cmd/dropafter/dropafter.go index 1a7a48da..07ccb96f 100644 --- a/cmd/dropafter/dropafter.go +++ b/cmd/dropafter/dropafter.go @@ -165,7 +165,7 @@ var errBadShaPrefix = errors.New("invalid prefix") var errBadShaLen = errors.New("invalid len") var errBadShaChar = errors.New("invalid character") -func parsesha(argstr string) (argtype int, height int32, psha *chainhash.Hash, err error) { +func parsesha(argstr string) (argtype int, height int64, psha *chainhash.Hash, err error) { var sha chainhash.Hash var hashbuf string @@ -187,7 +187,7 @@ func parsesha(argstr string) (argtype int, height int32, psha *chainhash.Hash, e var h int h, err = strconv.Atoi(argstr) if err == nil { - height = int32(h) + height = int64(h) return } log.Infof("Unable to parse height %v, err %v", height, err) diff --git a/cmd/findcheckpoint/findcheckpoint.go b/cmd/findcheckpoint/findcheckpoint.go index 25b8af04..2dc82c8e 100644 --- a/cmd/findcheckpoint/findcheckpoint.go +++ b/cmd/findcheckpoint/findcheckpoint.go @@ -67,7 +67,7 @@ func findCandidates(db database.Db, latestHash *chainhash.Hash) ([]*chaincfg.Che // The latest known block must be at least the last known checkpoint // plus required checkpoint confirmations. - checkpointConfirmations := int32(blockchain.CheckpointConfirmations) + checkpointConfirmations := int64(blockchain.CheckpointConfirmations) requiredHeight := latestCheckpoint.Height + checkpointConfirmations if block.Height() < requiredHeight { return nil, fmt.Errorf("the block database is only at height "+ @@ -92,7 +92,7 @@ func findCandidates(db database.Db, latestHash *chainhash.Hash) ([]*chaincfg.Che // Loop backwards through the chain to find checkpoint candidates. candidates := make([]*chaincfg.Checkpoint, 0, cfg.NumCandidates) - numTested := int32(0) + numTested := int64(0) for len(candidates) < cfg.NumCandidates && block.Height() > requiredHeight { // Display progress. if numTested%progressInterval == 0 { diff --git a/cmd/showblock/showblock.go b/cmd/showblock/showblock.go index 71136a4c..2a23ccdc 100644 --- a/cmd/showblock/showblock.go +++ b/cmd/showblock/showblock.go @@ -75,7 +75,7 @@ func netName(netParams *chaincfg.Params) string { } func main() { - end := int32(-1) + end := int64(-1) cfg := config{ DbType: "leveldb", @@ -165,7 +165,7 @@ func main() { } for ; height < end; height++ { - if cfg.Progress && height%int32(1) == 0 { + if cfg.Progress && height%int64(1) == 0 { log.Infof("Processing block %v", height) } err = DumpBlock(database, height, fo, cfg.RawBlock, cfg.FmtBlock, cfg.ShowTx) @@ -179,7 +179,7 @@ func main() { } } -func getHeight(database database.Db, str string) (int32, error) { +func getHeight(database database.Db, str string) (int64, error) { argtype, idx, sha, err := parsesha(str) if err != nil { log.Warnf("unable to decode [%v] %v", str, err) @@ -202,7 +202,7 @@ func getHeight(database database.Db, str string) (int32, error) { } // DumpBlock dumps the specified block. -func DumpBlock(database database.Db, height int32, fo io.Writer, rflag bool, fflag bool, tflag bool) error { +func DumpBlock(database database.Db, height int64, fo io.Writer, rflag bool, fflag bool, tflag bool) error { sha, err := database.FetchBlockShaByHeight(height) if err != nil { @@ -256,7 +256,7 @@ var ErrBadShaLen = errors.New("invalid len") // ErrBadShaChar is the error for an invalid character in a sha. var ErrBadShaChar = errors.New("invalid character") -func parsesha(argstr string) (argtype int, height int32, psha *chainhash.Hash, err error) { +func parsesha(argstr string) (argtype int, height int64, psha *chainhash.Hash, err error) { var sha chainhash.Hash var hashbuf string @@ -278,7 +278,7 @@ func parsesha(argstr string) (argtype int, height int32, psha *chainhash.Hash, e var h int h, err = strconv.Atoi(argstr) if err == nil { - height = int32(h) + height = int64(h) return } log.Infof("Unable to parse height %v, err %v", height, err) diff --git a/cpuminer.go b/cpuminer.go index 46f014d8..527d84c0 100644 --- a/cpuminer.go +++ b/cpuminer.go @@ -193,7 +193,9 @@ func (m *CPUMiner) submitBlock(block *dcrutil.Block) bool { // new transactions and enough time has elapsed without finding a solution. func (m *CPUMiner) solveBlock(msgBlock *wire.MsgBlock, ticker *time.Ticker, quit chan struct{}) bool { - blockHeight := int32(msgBlock.Header.Height) + + blockHeight := int64(msgBlock.Header.Height) + // Choose a random extra nonce offset for this block template and // worker. enOffset, err := wire.RandomUint64() diff --git a/database/common_test.go b/database/common_test.go index 6af3b5e4..cb623bf7 100644 --- a/database/common_test.go +++ b/database/common_test.go @@ -161,7 +161,7 @@ func loadBlocks(t *testing.T) ([]*dcrutil.Block, error) { // Create decoder from the buffer and a map to store the data bcDecoder := gob.NewDecoder(bcBuf) - blockchain := make(map[int32][]byte) + blockchain := make(map[int64][]byte) // Decode the blockchain into the map if err := bcDecoder.Decode(&blockchain); err != nil { @@ -169,7 +169,7 @@ func loadBlocks(t *testing.T) ([]*dcrutil.Block, error) { } blocks := make([]*dcrutil.Block, 0, len(blockchain)) - for height := int32(1); height < int32(len(blockchain)); height++ { + for height := int64(1); height < int64(len(blockchain)); height++ { block, err := dcrutil.NewBlockFromBytes(blockchain[height]) if err != nil { t.Errorf("failed to parse block %v", height) diff --git a/database/db.go b/database/db.go index 32c348c2..40b88d52 100644 --- a/database/db.go +++ b/database/db.go @@ -33,7 +33,7 @@ var ( // AllShas is a special value that can be used as the final sha when requesting // a range of shas by height to request them all. -const AllShas = int32(^uint32(0) >> 1) +const AllShas = int64(^uint64(0) >> 1) // Db defines a generic interface that is used to request and insert data into // the decred block chain. This interface is intended to be agnostic to actual @@ -58,7 +58,7 @@ type Db interface { FetchBlockBySha(sha *chainhash.Hash) (blk *dcrutil.Block, err error) // FetchBlockHeightBySha returns the block height for the given hash. - FetchBlockHeightBySha(sha *chainhash.Hash) (height int32, err error) + FetchBlockHeightBySha(sha *chainhash.Hash) (height int64, err error) // FetchBlockHeaderBySha returns a wire.BlockHeader for the given // sha. The implementation may cache the underlying data if desired. @@ -66,13 +66,13 @@ type Db interface { // FetchBlockShaByHeight returns a block hash based on its height in the // block chain. - FetchBlockShaByHeight(height int32) (sha *chainhash.Hash, err error) + FetchBlockShaByHeight(height int64) (sha *chainhash.Hash, err error) // FetchHeightRange looks up a range of blocks by the start and ending // heights. Fetch is inclusive of the start height and exclusive of the // ending height. To fetch all hashes from the start height until no // more are present, use the special id `AllShas'. - FetchHeightRange(startHeight, endHeight int32) (rshalist []chainhash.Hash, err error) + FetchHeightRange(startHeight, endHeight int64) (rshalist []chainhash.Hash, err error) // ExistsTxSha returns whether or not the given tx hash is present in // the database @@ -108,19 +108,19 @@ type Db interface { // into the database. The first block inserted into the database // will be treated as the genesis block. Every subsequent block insert // requires the referenced parent block to already exist. - InsertBlock(block *dcrutil.Block) (height int32, err error) + InsertBlock(block *dcrutil.Block) (height int64, err error) // NewestSha returns the hash and block height of the most recent (end) // block of the block chain. It will return the zero hash, -1 for // the block height, and no error (nil) if there are not any blocks in // the database yet. - NewestSha() (sha *chainhash.Hash, height int32, err error) + NewestSha() (sha *chainhash.Hash, height int64, err error) // FetchAddrIndexTip returns the hash and block height of the most recent // block which has had its address index populated. It will return // ErrAddrIndexDoesNotExist along with a zero hash, and -1 if the // addrindex hasn't yet been built up. - FetchAddrIndexTip() (sha *chainhash.Hash, height int32, err error) + FetchAddrIndexTip() (sha *chainhash.Hash, height int64, err error) // UpdateAddrIndexForBlock updates the stored addrindex with passed // index information for a particular block height. Additionally, it @@ -129,12 +129,12 @@ type Db interface { // transaction which is commited before the function returns. // Addresses are indexed by the raw bytes of their base58 decoded // hash160. - UpdateAddrIndexForBlock(blkSha *chainhash.Hash, height int32, + UpdateAddrIndexForBlock(blkSha *chainhash.Hash, height int64, addrIndex BlockAddrIndex) error // DropAddrIndexForBlock removes all passed address indexes and sets // the current block index below the previous HEAD. - DropAddrIndexForBlock(blkSha *chainhash.Hash, height int32, + DropAddrIndexForBlock(blkSha *chainhash.Hash, height int64, addrIndex BlockAddrIndex) error // FetchTxsForAddr looks up and returns all transactions which either @@ -173,7 +173,7 @@ type TxListReply struct { Sha *chainhash.Hash Tx *wire.MsgTx BlkSha *chainhash.Hash - Height int32 + Height int64 Index uint32 TxSpent []bool Err error diff --git a/database/interface_test.go b/database/interface_test.go index b600768a..e9ddba97 100644 --- a/database/interface_test.go +++ b/database/interface_test.go @@ -28,7 +28,7 @@ type testContext struct { t *testing.T dbType string db database.Db - blockHeight int32 + blockHeight int64 blockHash *chainhash.Hash block *dcrutil.Block useSpends bool @@ -215,7 +215,7 @@ func testFetchBlockShaByHeight(tc *testContext) bool { func testFetchBlockShaByHeightErrors(tc *testContext) bool { // Invalid heights must error and return a nil hash. - tests := []int32{-1, tc.blockHeight + 1, tc.blockHeight + 2} + tests := []int64{-1, tc.blockHeight + 1, tc.blockHeight + 2} for i, wantHeight := range tests { hashFromDb, err := tc.db.FetchBlockShaByHeight(wantHeight) if err == nil { @@ -964,7 +964,7 @@ func testInterface(t *testing.T, dbType string) { context := testContext{t: t, dbType: dbType, db: db} t.Logf("Loaded %d blocks for testing %s", len(blocks), dbType) - for height := int32(0); height < int32(len(blocks)); height++ { + for height := int64(0); height < int64(len(blocks)); height++ { // Get the appropriate block and hash and update the test // context accordingly. block := blocks[height] @@ -1000,7 +1000,7 @@ func testInterface(t *testing.T, dbType string) { // Run the data integrity tests again after all blocks have been // inserted to ensure the spend tracking is working properly. context.useSpends = true - for height := int32(0); height < int32(len(blocks)); height++ { + for height := int64(0); height < int64(len(blocks)); height++ { // Get the appropriate block and hash and update the // test context accordingly. block := blocks[height] @@ -1032,14 +1032,14 @@ func testInterface(t *testing.T, dbType string) { - DropAfterBlockBySha(*wire.ShaHash) (err error) x ExistsSha(sha *wire.ShaHash) (exists bool) x FetchBlockBySha(sha *wire.ShaHash) (blk *dcrutil.Block, err error) - x FetchBlockShaByHeight(height int32) (sha *wire.ShaHash, err error) + x FetchBlockShaByHeight(height int64) (sha *wire.ShaHash, err error) - FetchHeightRange(startHeight, endHeight int64) (rshalist []wire.ShaHash, err error) x ExistsTxSha(sha *wire.ShaHash) (exists bool) x FetchTxBySha(txsha *wire.ShaHash) ([]*TxListReply, error) x FetchTxByShaList(txShaList []*wire.ShaHash) []*TxListReply x FetchUnSpentTxByShaList(txShaList []*wire.ShaHash) []*TxListReply - x InsertBlock(block *dcrutil.Block) (height int32, err error) - x NewestSha() (sha *wire.ShaHash, height int32, err error) + x InsertBlock(block *dcrutil.Block) (height int64, err error) + x NewestSha() (sha *wire.ShaHash, height int64, err error) - RollbackClose() - Sync() */ diff --git a/database/ldb/block.go b/database/ldb/block.go index 74dab5fc..604df509 100644 --- a/database/ldb/block.go +++ b/database/ldb/block.go @@ -44,7 +44,7 @@ func (db *LevelDb) fetchBlockBySha(sha *chainhash.Hash) (blk *dcrutil.Block, err // FetchBlockHeightBySha returns the block height for the given hash. This is // part of the database.Db interface implementation. -func (db *LevelDb) FetchBlockHeightBySha(sha *chainhash.Hash) (int32, error) { +func (db *LevelDb) FetchBlockHeightBySha(sha *chainhash.Hash) (int64, error) { db.dbLock.Lock() defer db.dbLock.Unlock() @@ -74,7 +74,7 @@ func (db *LevelDb) FetchBlockHeaderBySha(sha *chainhash.Hash) (bh *wire.BlockHea return bh, err } -func (db *LevelDb) getBlkLoc(sha *chainhash.Hash) (int32, error) { +func (db *LevelDb) getBlkLoc(sha *chainhash.Hash) (int64, error) { key := shaBlkToKey(sha) data, err := db.lDb.Get(key, db.ro) @@ -88,13 +88,13 @@ func (db *LevelDb) getBlkLoc(sha *chainhash.Hash) (int32, error) { // deserialize blkHeight := binary.LittleEndian.Uint64(data) - return int32(blkHeight), nil + return int64(blkHeight), nil } -func (db *LevelDb) getBlkByHeight(blkHeight int32) (rsha *chainhash.Hash, rbuf []byte, err error) { +func (db *LevelDb) getBlkByHeight(blkHeight int64) (rsha *chainhash.Hash, rbuf []byte, err error) { var blkVal []byte - key := int64ToKey(int64(blkHeight)) + key := int64ToKey(blkHeight) blkVal, err = db.lDb.Get(key, db.ro) if err != nil { @@ -112,8 +112,8 @@ func (db *LevelDb) getBlkByHeight(blkHeight int32) (rsha *chainhash.Hash, rbuf [ return &sha, blockdata, nil } -func (db *LevelDb) getBlk(sha *chainhash.Hash) (rblkHeight int32, rbuf []byte, err error) { - var blkHeight int32 +func (db *LevelDb) getBlk(sha *chainhash.Hash) (rblkHeight int64, rbuf []byte, err error) { + var blkHeight int64 blkHeight, err = db.getBlkLoc(sha) if err != nil { @@ -129,13 +129,13 @@ func (db *LevelDb) getBlk(sha *chainhash.Hash) (rblkHeight int32, rbuf []byte, e return blkHeight, buf, nil } -func (db *LevelDb) setBlk(sha *chainhash.Hash, blkHeight int32, buf []byte) { +func (db *LevelDb) setBlk(sha *chainhash.Hash, blkHeight int64, buf []byte) { // serialize var lw [8]byte binary.LittleEndian.PutUint64(lw[0:8], uint64(blkHeight)) shaKey := shaBlkToKey(sha) - blkKey := int64ToKey(int64(blkHeight)) + blkKey := int64ToKey(blkHeight) blkVal := make([]byte, len(sha)+len(buf)) copy(blkVal[0:], sha[:]) @@ -148,7 +148,7 @@ func (db *LevelDb) setBlk(sha *chainhash.Hash, blkHeight int32, buf []byte) { // insertSha stores a block hash and its associated data block with a // previous sha of `prevSha'. // insertSha shall be called with db lock held -func (db *LevelDb) insertBlockData(sha *chainhash.Hash, prevSha *chainhash.Hash, buf []byte) (int32, error) { +func (db *LevelDb) insertBlockData(sha *chainhash.Hash, prevSha *chainhash.Hash, buf []byte) (int64, error) { oBlkHeight, err := db.getBlkLoc(prevSha) if err != nil { // check current block count @@ -178,8 +178,8 @@ func (db *LevelDb) insertBlockData(sha *chainhash.Hash, prevSha *chainhash.Hash, // fetchSha returns the datablock for the given ShaHash. func (db *LevelDb) fetchSha(sha *chainhash.Hash) (rbuf []byte, - rblkHeight int32, err error) { - var blkHeight int32 + rblkHeight int64, err error) { + var blkHeight int64 var buf []byte blkHeight, buf, err = db.getBlk(sha) @@ -211,7 +211,7 @@ func (db *LevelDb) blkExistsSha(sha *chainhash.Hash) (bool, error) { // FetchBlockShaByHeight returns a block hash based on its height in the // block chain. -func (db *LevelDb) FetchBlockShaByHeight(height int32) (sha *chainhash.Hash, err error) { +func (db *LevelDb) FetchBlockShaByHeight(height int64) (sha *chainhash.Hash, err error) { db.dbLock.Lock() defer db.dbLock.Unlock() @@ -220,8 +220,8 @@ func (db *LevelDb) FetchBlockShaByHeight(height int32) (sha *chainhash.Hash, err // fetchBlockShaByHeight returns a block hash based on its height in the // block chain. -func (db *LevelDb) fetchBlockShaByHeight(height int32) (rsha *chainhash.Hash, err error) { - key := int64ToKey(int64(height)) +func (db *LevelDb) fetchBlockShaByHeight(height int64) (rsha *chainhash.Hash, err error) { + key := int64ToKey(height) blkVal, err := db.lDb.Get(key, db.ro) if err != nil { @@ -239,11 +239,11 @@ func (db *LevelDb) fetchBlockShaByHeight(height int32) (rsha *chainhash.Hash, er // heights. Fetch is inclusive of the start height and exclusive of the // ending height. To fetch all hashes from the start height until no // more are present, use the special id `AllShas'. -func (db *LevelDb) FetchHeightRange(startHeight, endHeight int32) (rshalist []chainhash.Hash, err error) { +func (db *LevelDb) FetchHeightRange(startHeight, endHeight int64) (rshalist []chainhash.Hash, err error) { db.dbLock.Lock() defer db.dbLock.Unlock() - var endidx int32 + var endidx int64 if endHeight == database.AllShas { endidx = startHeight + 500 } else { @@ -254,7 +254,7 @@ func (db *LevelDb) FetchHeightRange(startHeight, endHeight int32) (rshalist []ch for height := startHeight; height < endidx; height++ { // TODO(drahn) fix blkFile from height - key := int64ToKey(int64(height)) + key := int64ToKey(height) blkVal, lerr := db.lDb.Get(key, db.ro) if lerr != nil { break @@ -276,7 +276,7 @@ func (db *LevelDb) FetchHeightRange(startHeight, endHeight int32) (rshalist []ch // NewestSha returns the hash and block height of the most recent (end) block of // the block chain. It will return the zero hash, -1 for the block height, and // no error (nil) if there are not any blocks in the database yet. -func (db *LevelDb) NewestSha() (rsha *chainhash.Hash, rblkid int32, err error) { +func (db *LevelDb) NewestSha() (rsha *chainhash.Hash, rblkid int64, err error) { db.dbLock.Lock() defer db.dbLock.Unlock() @@ -315,7 +315,7 @@ func (db *LevelDb) checkAddrIndexVersion() error { // updated accordingly by functions that modify the state. This function is // used on start up to load the info into memory. Callers will use the public // version of this function below, which returns our cached copy. -func (db *LevelDb) fetchAddrIndexTip() (*chainhash.Hash, int32, error) { +func (db *LevelDb) fetchAddrIndexTip() (*chainhash.Hash, int64, error) { db.dbLock.Lock() defer db.dbLock.Unlock() @@ -329,14 +329,14 @@ func (db *LevelDb) fetchAddrIndexTip() (*chainhash.Hash, int32, error) { blkHeight := binary.LittleEndian.Uint64(data[32:]) - return &blkSha, int32(blkHeight), nil + return &blkSha, int64(blkHeight), nil } // FetchAddrIndexTip returns the hash and block height of the most recent // block whose transactions have been indexed by address. It will return // ErrAddrIndexDoesNotExist along with a zero hash, and -1 if the // addrindex hasn't yet been built up. -func (db *LevelDb) FetchAddrIndexTip() (*chainhash.Hash, int32, error) { +func (db *LevelDb) FetchAddrIndexTip() (*chainhash.Hash, int64, error) { db.dbLock.Lock() defer db.dbLock.Unlock() diff --git a/database/ldb/dup_test.go b/database/ldb/dup_test.go index aee2eaf8..b60172c4 100644 --- a/database/ldb/dup_test.go +++ b/database/ldb/dup_test.go @@ -62,7 +62,7 @@ func Test_dupTx(t *testing.T) { // Populate with the fisrt 256 blocks, so we have blocks to 'mess with' err = nil out: - for height := int32(0); height < int32(len(blocks)); height++ { + for height := int64(0); height < int64(len(blocks)); height++ { block := blocks[height] if height != 0 { // except for NoVerify which does not allow lookups check inputs diff --git a/database/ldb/insertremove_test.go b/database/ldb/insertremove_test.go index 358b4526..e9854842 100644 --- a/database/ldb/insertremove_test.go +++ b/database/ldb/insertremove_test.go @@ -66,7 +66,7 @@ func testUnspentInsertStakeTree(t *testing.T) { }() blocks := loadblocks(t) endtest: - for height := int32(0); height < int32(len(blocks))-1; height++ { + for height := int64(0); height < int64(len(blocks))-1; height++ { block := blocks[height] var txneededList []*chainhash.Hash @@ -322,7 +322,7 @@ func testUnspentInsertRegTree(t *testing.T) { }() blocks := loadblocks(t) endtest: - for height := int32(0); height < int32(len(blocks))-1; height++ { + for height := int64(0); height < int64(len(blocks))-1; height++ { block := blocks[height] // jam in genesis block diff --git a/database/ldb/leveldb.go b/database/ldb/leveldb.go index 7e34ec96..74ce3f4d 100644 --- a/database/ldb/leveldb.go +++ b/database/ldb/leveldb.go @@ -31,7 +31,7 @@ var log = btclog.Disabled type tTxInsertData struct { txsha *chainhash.Hash - blockid int32 + blockid int64 txoff int txlen int usedbuf []byte @@ -49,14 +49,14 @@ type LevelDb struct { lbatch *leveldb.Batch - nextBlock int32 + nextBlock int64 lastBlkShaCached bool lastBlkSha chainhash.Hash - lastBlkIdx int32 + lastBlkIdx int64 lastAddrIndexBlkSha chainhash.Hash - lastAddrIndexBlkIdx int32 + lastAddrIndexBlkIdx int64 txUpdateMap map[chainhash.Hash]*txUpdateObj txSpentUpdateMap map[chainhash.Hash]*spentTxUpdate @@ -100,9 +100,9 @@ func OpenDB(args ...interface{}) (database.Db, error) { } // Need to find last block and tx - var lastknownblock, nextunknownblock, testblock int32 + var lastknownblock, nextunknownblock, testblock int64 - increment := int32(100000) + increment := int64(100000) ldb := db.(*LevelDb) var lastSha *chainhash.Hash @@ -380,7 +380,7 @@ func (db *LevelDb) DropAfterBlockBySha(sha *chainhash.Hash) (rerr error) { } db.lBatch().Delete(shaBlkToKey(blksha)) - db.lBatch().Delete(int64ToKey(int64(height))) + db.lBatch().Delete(int64ToKey(height)) } // update the last block cache @@ -396,7 +396,7 @@ func (db *LevelDb) DropAfterBlockBySha(sha *chainhash.Hash) (rerr error) { // database. The first block inserted into the database will be treated as the // genesis block. Every subsequent block insert requires the referenced parent // block to already exist. -func (db *LevelDb) InsertBlock(block *dcrutil.Block) (height int32, rerr error) { +func (db *LevelDb) InsertBlock(block *dcrutil.Block) (height int64, rerr error) { // Be careful with this function on syncs. It contains decred changes. // Obtain the previous block first so long as it's not the genesis block diff --git a/database/ldb/operational_test.go b/database/ldb/operational_test.go index ce1c85d9..994e4cb7 100644 --- a/database/ldb/operational_test.go +++ b/database/ldb/operational_test.go @@ -74,7 +74,7 @@ func TestOperational(t *testing.T) { // testAddrIndexOperations ensures that all normal operations concerning // the optional address index function correctly. -func testAddrIndexOperations(t *testing.T, db database.Db, newestBlock *dcrutil.Block, newestSha *chainhash.Hash, newestBlockIdx int32) { +func testAddrIndexOperations(t *testing.T, db database.Db, newestBlock *dcrutil.Block, newestSha *chainhash.Hash, newestBlockIdx int64) { // Metadata about the current addr index state should be unset. sha, height, err := db.FetchAddrIndexTip() if err != database.ErrAddrIndexDoesNotExist { @@ -197,7 +197,7 @@ func testAddrIndexOperations(t *testing.T, db database.Db, newestBlock *dcrutil. } -func assertAddrIndexTipIsUpdated(db database.Db, t *testing.T, newestSha *chainhash.Hash, newestBlockIdx int32) { +func assertAddrIndexTipIsUpdated(db database.Db, t *testing.T, newestSha *chainhash.Hash, newestBlockIdx int64) { // Safe to ignore error, since height will be < 0 in "error" case. sha, height, _ := db.FetchAddrIndexTip() if newestBlockIdx != height { @@ -224,7 +224,7 @@ func testOperationalMode(t *testing.T) { defer testDb.cleanUpFunc() err = nil out: - for height := int32(0); height < int32(len(testDb.blocks)); height++ { + for height := int64(0); height < int64(len(testDb.blocks)); height++ { block := testDb.blocks[height] if height != 0 { // except for NoVerify which does not allow lookups check inputs @@ -369,7 +369,7 @@ func testBackout(t *testing.T) { } err = nil - for height := int32(0); height < int32(len(testDb.blocks)); height++ { + for height := int64(0); height < int64(len(testDb.blocks)); height++ { if height == 100 { testDb.db.Sync() } @@ -460,14 +460,14 @@ func loadBlocks(t *testing.T, file string) (blocks []*dcrutil.Block, err error) // Create decoder from the buffer and a map to store the data bcDecoder := gob.NewDecoder(bcBuf) - blockchain := make(map[int32][]byte) + blockchain := make(map[int64][]byte) // Decode the blockchain into the map if err := bcDecoder.Decode(&blockchain); err != nil { t.Errorf("error decoding test blockchain") } blocks = make([]*dcrutil.Block, 0, len(blockchain)) - for height := int32(1); height < int32(len(blockchain)); height++ { + for height := int64(1); height < int64(len(blockchain)); height++ { block, err := dcrutil.NewBlockFromBytes(blockchain[height]) if err != nil { t.Errorf("failed to parse block %v", height) @@ -482,18 +482,18 @@ func loadBlocks(t *testing.T, file string) (blocks []*dcrutil.Block, err error) func testFetchHeightRange(t *testing.T, db database.Db, blocks []*dcrutil.Block) { - var testincrement int32 = 50 - var testcnt int32 = 100 + var testincrement int64 = 50 + var testcnt int64 = 100 shanames := make([]*chainhash.Hash, len(blocks)) - nBlocks := int32(len(blocks)) + nBlocks := int64(len(blocks)) for i := range blocks { shanames[i] = blocks[i].Sha() } - for startheight := int32(0); startheight < nBlocks; startheight += testincrement { + for startheight := int64(0); startheight < nBlocks; startheight += testincrement { endheight := startheight + testcnt if endheight > nBlocks { @@ -506,20 +506,20 @@ func testFetchHeightRange(t *testing.T, db database.Db, blocks []*dcrutil.Block) } if endheight == database.AllShas { - if int32(len(shalist)) != nBlocks-startheight { + if int64(len(shalist)) != nBlocks-startheight { t.Errorf("FetchHeightRange: expected A %v shas, got %v", nBlocks-startheight, len(shalist)) } } else { - if int32(len(shalist)) != testcnt { + if int64(len(shalist)) != testcnt { t.Errorf("FetchHeightRange: expected %v shas, got %v", testcnt, len(shalist)) } } for i := range shalist { - sha0 := *shanames[int32(i)+startheight] + sha0 := *shanames[int64(i)+startheight] sha1 := shalist[i] if sha0 != sha1 { - t.Errorf("FetchHeightRange: mismatch sha at %v requested range %v %v: %v %v ", int32(i)+startheight, startheight, endheight, sha0, sha1) + t.Errorf("FetchHeightRange: mismatch sha at %v requested range %v %v: %v %v ", int64(i)+startheight, startheight, endheight, sha0, sha1) } } } diff --git a/database/ldb/tx.go b/database/ldb/tx.go index 977c8137..b60cb2ef 100644 --- a/database/ldb/tx.go +++ b/database/ldb/tx.go @@ -50,7 +50,7 @@ var addrIndexVersionKey = []byte("addrindexversion") type txUpdateObj struct { txSha *chainhash.Hash - blkHeight int32 + blkHeight int64 blkIndex uint32 txoff int txlen int @@ -60,7 +60,7 @@ type txUpdateObj struct { } type spentTx struct { - blkHeight int32 + blkHeight int64 blkIndex uint32 txoff int txlen int @@ -73,7 +73,7 @@ type spentTxUpdate struct { } // InsertTx inserts a tx hash and its associated data into the database. -func (db *LevelDb) InsertTx(txsha *chainhash.Hash, height int32, idx uint32, txoff int, txlen int, spentbuf []byte) (err error) { +func (db *LevelDb) InsertTx(txsha *chainhash.Hash, height int64, idx uint32, txoff int, txlen int, spentbuf []byte) (err error) { db.dbLock.Lock() defer db.dbLock.Unlock() @@ -82,7 +82,7 @@ func (db *LevelDb) InsertTx(txsha *chainhash.Hash, height int32, idx uint32, txo // insertTx inserts a tx hash and its associated data into the database. // Must be called with db lock held. -func (db *LevelDb) insertTx(txSha *chainhash.Hash, height int32, idx uint32, txoff int, txlen int, spentbuf []byte) (err error) { +func (db *LevelDb) insertTx(txSha *chainhash.Hash, height int64, idx uint32, txoff int, txlen int, spentbuf []byte) (err error) { var txU txUpdateObj txU.txSha = txSha @@ -115,7 +115,7 @@ func (db *LevelDb) formatTx(txu *txUpdateObj) []byte { return txW[:] } -func (db *LevelDb) getTxData(txsha *chainhash.Hash) (int32, uint32, int, int, []byte, error) { +func (db *LevelDb) getTxData(txsha *chainhash.Hash) (int64, uint32, int, int, []byte, error) { key := shaTxToKey(txsha) buf, err := db.lDb.Get(key, db.ro) if err != nil { @@ -130,7 +130,7 @@ func (db *LevelDb) getTxData(txsha *chainhash.Hash) (int32, uint32, int, int, [] spentBuf := make([]byte, len(buf)-20) copy(spentBuf, buf[20:]) - return int32(blkHeight), blkIndex, int(txOff), int(txLen), spentBuf, nil + return int64(blkHeight), blkIndex, int(txOff), int(txLen), spentBuf, nil } func (db *LevelDb) getTxFullySpent(txsha *chainhash.Hash) ([]*spentTx, error) { @@ -157,7 +157,7 @@ func (db *LevelDb) getTxFullySpent(txsha *chainhash.Hash) ([]*spentTx, error) { numTxO := binary.LittleEndian.Uint32(buf[offset+20 : offset+24]) sTx := spentTx{ - blkHeight: int32(blkHeight), + blkHeight: int64(blkHeight), blkIndex: blkIndex, txoff: int(txOff), txlen: int(txLen), @@ -278,8 +278,8 @@ func (db *LevelDb) FetchUnSpentTxByShaList(txShaList []*chainhash.Hash) []*datab } // fetchTxDataBySha returns several pieces of data regarding the given sha. -func (db *LevelDb) fetchTxDataBySha(txsha *chainhash.Hash) (rtx *wire.MsgTx, rblksha *chainhash.Hash, rheight int32, ridx uint32, rtxspent []byte, err error) { - var blkHeight int32 +func (db *LevelDb) fetchTxDataBySha(txsha *chainhash.Hash) (rtx *wire.MsgTx, rblksha *chainhash.Hash, rheight int64, ridx uint32, rtxspent []byte, err error) { + var blkHeight int64 var blkIndex uint32 var txspent []byte var txOff, txLen int @@ -298,7 +298,7 @@ func (db *LevelDb) fetchTxDataBySha(txsha *chainhash.Hash) (rtx *wire.MsgTx, rbl // fetchTxDataByLoc returns several pieces of data regarding the given tx // located by the block/offset/size location -func (db *LevelDb) fetchTxDataByLoc(blkHeight int32, txOff int, txLen int, txspent []byte) (rtx *wire.MsgTx, rblksha *chainhash.Hash, rheight int32, rtxspent []byte, err error) { +func (db *LevelDb) fetchTxDataByLoc(blkHeight int64, txOff int, txLen int, txspent []byte) (rtx *wire.MsgTx, rblksha *chainhash.Hash, rheight int64, rtxspent []byte, err error) { var blksha *chainhash.Hash var blkbuf []byte @@ -502,7 +502,7 @@ func (db *LevelDb) FetchTxsForAddr(addr dcrutil.Address, skip int, addrIndex := unpackTxIndex(rawIndex) tx, blkSha, blkHeight, _, err := db.fetchTxDataByLoc( - int32(addrIndex.Height), + int64(addrIndex.Height), int(addrIndex.TxOffset), int(addrIndex.TxLen), []byte{}) @@ -547,7 +547,7 @@ func (db *LevelDb) FetchTxsForAddr(addr dcrutil.Address, skip int, // overhead when storing and retrieving since the entire list must // be fetched each time. func (db *LevelDb) UpdateAddrIndexForBlock(blkSha *chainhash.Hash, - blkHeight int32, addrIndexes database.BlockAddrIndex) error { + blkHeight int64, addrIndexes database.BlockAddrIndex) error { db.dbLock.Lock() defer db.dbLock.Unlock() @@ -587,7 +587,7 @@ func (db *LevelDb) UpdateAddrIndexForBlock(blkSha *chainhash.Hash, // DropAddrIndexForBlock drops the address index db for a given block/height. func (db *LevelDb) DropAddrIndexForBlock(blkSha *chainhash.Hash, - blkHeight int32, addrIndexes database.BlockAddrIndex) (rerr error) { + blkHeight int64, addrIndexes database.BlockAddrIndex) (rerr error) { db.dbLock.Lock() defer db.dbLock.Unlock() defer db.lbatch.Reset() diff --git a/database/memdb/memdb.go b/database/memdb/memdb.go index a3f14322..48ced352 100644 --- a/database/memdb/memdb.go +++ b/database/memdb/memdb.go @@ -30,7 +30,7 @@ var ( // a transaction. type tTxInsertData struct { tree int8 - blockHeight int32 + blockHeight int64 offset int spentBuf []bool } @@ -84,7 +84,7 @@ type MemDb struct { // blocksBySha keeps track of block heights by hash. The height can // be used as an index into the blocks slice. - blocksBySha map[chainhash.Hash]int32 + blocksBySha map[chainhash.Hash]int64 // txns holds information about transactions such as which their // block height and spent status of all their outputs. @@ -175,7 +175,7 @@ func (db *MemDb) DropAfterBlockBySha(sha *chainhash.Hash) error { // backwards from the last block through the block just after the passed // block. While doing this unspend all transactions in each block and // remove the block. - endHeight := int32(len(db.blocks) - 1) + endHeight := int64(len(db.blocks) - 1) for i := endHeight; i > height; i-- { blk := db.blocks[i] @@ -247,7 +247,7 @@ func (db *MemDb) fetchBlockBySha(sha *chainhash.Hash) (*dcrutil.Block, error) { // FetchBlockHeightBySha returns the block height for the given hash. This is // part of the database.Db interface implementation. -func (db *MemDb) FetchBlockHeightBySha(sha *chainhash.Hash) (int32, error) { +func (db *MemDb) FetchBlockHeightBySha(sha *chainhash.Hash) (int64, error) { db.Lock() defer db.Unlock() @@ -285,7 +285,7 @@ func (db *MemDb) FetchBlockHeaderBySha(sha *chainhash.Hash) (*wire.BlockHeader, // FetchBlockShaByHeight returns a block hash based on its height in the block // chain. This is part of the database.Db interface implementation. -func (db *MemDb) FetchBlockShaByHeight(height int32) (*chainhash.Hash, error) { +func (db *MemDb) FetchBlockShaByHeight(height int64) (*chainhash.Hash, error) { db.Lock() defer db.Unlock() @@ -293,7 +293,7 @@ func (db *MemDb) FetchBlockShaByHeight(height int32) (*chainhash.Hash, error) { return nil, ErrDbClosed } - numBlocks := int32(len(db.blocks)) + numBlocks := int64(len(db.blocks)) if height < 0 || height > numBlocks-1 { return nil, fmt.Errorf("unable to fetch block height %d since "+ "it is not within the valid range (%d-%d)", height, 0, @@ -309,7 +309,7 @@ func (db *MemDb) FetchBlockShaByHeight(height int32) (*chainhash.Hash, error) { // Fetch is inclusive of the start height and exclusive of the ending height. // To fetch all hashes from the start height until no more are present, use the // special id `AllShas'. This is part of the database.Db interface implementation. -func (db *MemDb) FetchHeightRange(startHeight, endHeight int32) ([]chainhash.Hash, error) { +func (db *MemDb) FetchHeightRange(startHeight, endHeight int64) ([]chainhash.Hash, error) { db.Lock() defer db.Unlock() @@ -320,7 +320,7 @@ func (db *MemDb) FetchHeightRange(startHeight, endHeight int32) ([]chainhash.Has // When the user passes the special AllShas id, adjust the end height // accordingly. if endHeight == database.AllShas { - endHeight = int32(len(db.blocks)) + endHeight = int64(len(db.blocks)) } // Ensure requested heights are sane. @@ -335,7 +335,7 @@ func (db *MemDb) FetchHeightRange(startHeight, endHeight int32) ([]chainhash.Has } // Fetch as many as are availalbe within the specified range. - lastBlockIndex := int32(len(db.blocks) - 1) + lastBlockIndex := int64(len(db.blocks) - 1) hashList := make([]chainhash.Hash, 0, endHeight-startHeight) for i := startHeight; i < endHeight; i++ { if i > lastBlockIndex { @@ -540,7 +540,7 @@ func (db *MemDb) FetchUnSpentTxByShaList(txShaList []*chainhash.Hash) []*databas // genesis block. Every subsequent block insert requires the referenced parent // block to already exist. This is part of the database.Db interface // implementation. -func (db *MemDb) InsertBlock(block *dcrutil.Block) (int32, error) { +func (db *MemDb) InsertBlock(block *dcrutil.Block) (int64, error) { db.Lock() defer db.Unlock() @@ -576,7 +576,7 @@ func (db *MemDb) InsertBlock(block *dcrutil.Block) (int32, error) { // Build a map of in-flight transactions because some of the inputs in // this block could be referencing other transactions earlier in this // block which are not yet in the chain. - newHeight := int32(len(db.blocks)) + newHeight := int64(len(db.blocks)) txInFlight := map[chainhash.Hash]int{} // Loop through all transactions and inputs to ensure there are no error // conditions that would prevent them from be inserted into the db. @@ -707,7 +707,7 @@ func (db *MemDb) InsertBlock(block *dcrutil.Block) (int32, error) { // the block chain. It will return the zero hash, -1 for the block height, and // no error (nil) if there are not any blocks in the database yet. This is part // of the database.Db interface implementation. -func (db *MemDb) NewestSha() (*chainhash.Hash, int32, error) { +func (db *MemDb) NewestSha() (*chainhash.Hash, int64, error) { db.Lock() defer db.Unlock() @@ -723,25 +723,25 @@ func (db *MemDb) NewestSha() (*chainhash.Hash, int32, error) { } blockSha := db.blocks[numBlocks-1].BlockSha() - return &blockSha, int32(numBlocks - 1), nil + return &blockSha, int64(numBlocks - 1), nil } // FetchAddrIndexTip isn't currently implemented. This is a part of the // database.Db interface implementation. -func (db *MemDb) FetchAddrIndexTip() (*chainhash.Hash, int32, error) { +func (db *MemDb) FetchAddrIndexTip() (*chainhash.Hash, int64, error) { return nil, 0, database.ErrNotImplemented } // UpdateAddrIndexForBlock isn't currently implemented. This is a part of the // database.Db interface implementation. -func (db *MemDb) UpdateAddrIndexForBlock(*chainhash.Hash, int32, +func (db *MemDb) UpdateAddrIndexForBlock(*chainhash.Hash, int64, database.BlockAddrIndex) error { return database.ErrNotImplemented } // DropAddrIndexForBlock isn't currently implemented. This is a part of the // database.Db interface implementation. -func (db *MemDb) DropAddrIndexForBlock(*chainhash.Hash, int32, +func (db *MemDb) DropAddrIndexForBlock(*chainhash.Hash, int64, database.BlockAddrIndex) error { return database.ErrNotImplemented } @@ -795,7 +795,7 @@ func (db *MemDb) Sync() error { func newMemDb() *MemDb { db := MemDb{ blocks: make([]*wire.MsgBlock, 0, 200000), - blocksBySha: make(map[chainhash.Hash]int32), + blocksBySha: make(map[chainhash.Hash]int64), txns: make(map[chainhash.Hash][]*tTxInsertData), } return &db diff --git a/database/reorg_test.go b/database/reorg_test.go index d12d3c8a..f849c34b 100644 --- a/database/reorg_test.go +++ b/database/reorg_test.go @@ -39,17 +39,17 @@ func testReorganization(t *testing.T, dbType string) { // Find where chain forks var forkHash chainhash.Hash - var forkHeight int32 + var forkHeight int64 for i, _ := range blocks { if blocks[i].Sha().IsEqual(blocksReorg[i].Sha()) { blkHash := blocks[i].Sha() forkHash = *blkHash - forkHeight = int32(i) + forkHeight = int64(i) } } // Insert all blocks from chain 1 - for i := int32(0); i < int32(len(blocks)); i++ { + for i := int64(0); i < int64(len(blocks)); i++ { blkHash := blocks[i].Sha() if err != nil { t.Fatalf("Error getting SHA for block %dA: %v", i-2, err) @@ -68,7 +68,7 @@ func testReorganization(t *testing.T, dbType string) { } // Insert blocks from the other chain to simulate a reorg - for i := forkHeight + 1; i < int32(len(blocksReorg)); i++ { + for i := forkHeight + 1; i < int64(len(blocksReorg)); i++ { blkHash := blocksReorg[i].Sha() if err != nil { t.Fatalf("Error getting SHA for block %dA: %v", i-2, err) @@ -84,7 +84,7 @@ func testReorganization(t *testing.T, dbType string) { t.Fatalf("Error getting newest block info") } - for i := int32(0); i <= maxHeight; i++ { + for i := int64(0); i <= maxHeight; i++ { blkHash, err := db.FetchBlockShaByHeight(i) if err != nil { t.Fatalf("Error fetching SHA for block %d: %v", i, err) @@ -132,7 +132,7 @@ func loadReorgBlocks(filename string) ([]*dcrutil.Block, error) { // Create decoder from the buffer and a map to store the data bcDecoder := gob.NewDecoder(bcBuf) - blockchain := make(map[int32][]byte) + blockchain := make(map[int64][]byte) // Decode the blockchain into the map if err := bcDecoder.Decode(&blockchain); err != nil { @@ -142,7 +142,7 @@ func loadReorgBlocks(filename string) ([]*dcrutil.Block, error) { var block *dcrutil.Block blocks := make([]*dcrutil.Block, 0, len(blockchain)) - for height := int32(0); height < int32(len(blockchain)); height++ { + for height := int64(0); height < int64(len(blockchain)); height++ { block, err = dcrutil.NewBlockFromBytes(blockchain[height]) if err != nil { return blocks, err diff --git a/dcrjson/chainsvrcmds.go b/dcrjson/chainsvrcmds.go index 1d08bc99..ac1a59f1 100644 --- a/dcrjson/chainsvrcmds.go +++ b/dcrjson/chainsvrcmds.go @@ -187,21 +187,6 @@ func NewGetBlockHashCmd(index int64) *GetBlockHashCmd { } } -// GetBlockHeaderCmd defines the getblockheader JSON-RPC command. -type GetBlockHeaderCmd struct { - Hash string - Verbose *bool `jsonrpcdefault:"true"` -} - -// NewGetBlockHeaderCmd returns a new instance which can be used to issue a -// getblockheader JSON-RPC command. -func NewGetBlockHeaderCmd(hash string, verbose *bool) *GetBlockHeaderCmd { - return &GetBlockHeaderCmd{ - Hash: hash, - Verbose: verbose, - } -} - // TemplateRequest is a request object as defined in BIP22 // (https://en.bitcoin.it/wiki/BIP_0022), it is optionally provided as an // pointer argument to GetBlockTemplateCmd. @@ -749,7 +734,6 @@ func init() { MustRegisterCmd("getblockchaininfo", (*GetBlockChainInfoCmd)(nil), flags) MustRegisterCmd("getblockcount", (*GetBlockCountCmd)(nil), flags) MustRegisterCmd("getblockhash", (*GetBlockHashCmd)(nil), flags) - MustRegisterCmd("getblockheader", (*GetBlockHeaderCmd)(nil), flags) MustRegisterCmd("getblocktemplate", (*GetBlockTemplateCmd)(nil), flags) MustRegisterCmd("getchaintips", (*GetChainTipsCmd)(nil), flags) MustRegisterCmd("getconnectioncount", (*GetConnectionCountCmd)(nil), flags) diff --git a/dcrjson/chainsvrcmds_test.go b/dcrjson/chainsvrcmds_test.go index 3d0301cc..101725e4 100644 --- a/dcrjson/chainsvrcmds_test.go +++ b/dcrjson/chainsvrcmds_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2014 The dcrsuite developers +// Copyright (c) 2014 The btcsuite developers // Copyright (c) 2015 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -200,20 +200,6 @@ func TestChainSvrCmds(t *testing.T) { marshalled: `{"jsonrpc":"1.0","method":"getblockhash","params":[123],"id":1}`, unmarshalled: &dcrjson.GetBlockHashCmd{Index: 123}, }, - { - name: "getblockheader", - newCmd: func() (interface{}, error) { - return dcrjson.NewCmd("getblockheader", "123") - }, - staticCmd: func() interface{} { - return dcrjson.NewGetBlockHeaderCmd("123", nil) - }, - marshalled: `{"jsonrpc":"1.0","method":"getblockheader","params":["123"],"id":1}`, - unmarshalled: &dcrjson.GetBlockHeaderCmd{ - Hash: "123", - Verbose: dcrjson.Bool(true), - }, - }, { name: "getblocktemplate", newCmd: func() (interface{}, error) { @@ -955,7 +941,6 @@ func TestChainSvrCmds(t *testing.T) { t.Errorf("Test #%d (%s) unexpected marshalled data - "+ "got %s, want %s", i, test.name, marshalled, test.marshalled) - t.Errorf("\n%s\n%s", marshalled, test.marshalled) continue } diff --git a/dcrjson/chainsvrresults.go b/dcrjson/chainsvrresults.go index 607327db..fcf373b8 100644 --- a/dcrjson/chainsvrresults.go +++ b/dcrjson/chainsvrresults.go @@ -7,31 +7,14 @@ package dcrjson import "encoding/json" -// GetBlockHeaderVerboseResult models the data from the getblockheader command when -// the verbose flag is set. When the verbose flag is not set, getblockheader -// returns a hex-encoded string. -type GetBlockHeaderVerboseResult struct { - Hash string `json:"hash"` - Confirmations uint32 `json:"confirmations"` - Height int32 `json:"height"` - Version int32 `json:"version"` - MerkleRoot string `json:"merkleroot"` - Time int64 `json:"time"` - Nonce uint64 `json:"nonce"` - Bits string `json:"bits"` - Difficulty float64 `json:"difficulty"` - PreviousHash string `json:"previousblockhash,omitempty"` - NextHash string `json:"nextblockhash,omitempty"` -} - // GetBlockVerboseResult models the data from the getblock command when the // verbose flag is set. When the verbose flag is not set, getblock returns a // hex-encoded string. Contains Decred additions. type GetBlockVerboseResult struct { Hash string `json:"hash"` - Confirmations uint32 `json:"confirmations"` + Confirmations uint64 `json:"confirmations"` Size int32 `json:"size"` - Height int32 `json:"height"` + Height int64 `json:"height"` Version int32 `json:"version"` MerkleRoot string `json:"merkleroot"` StakeRoot string `json:"stakeroot"` @@ -152,13 +135,6 @@ type GetBlockTemplateResult struct { RejectReasion string `json:"reject-reason,omitempty"` } -// GetMempoolInfoResult models the data returned from the getmempoolinfo -// command. -type GetMempoolInfoResult struct { - Size int64 `json:"size"` - Bytes int64 `json:"bytes"` -} - // GetNetworkInfoResult models the data returned from the getnetworkinfo // command. type GetNetworkInfoResult struct { @@ -201,7 +177,7 @@ type GetRawMempoolVerboseResult struct { Size int32 `json:"size"` Fee float64 `json:"fee"` Time int64 `json:"time"` - Height int32 `json:"height"` + Height int64 `json:"height"` StartingPriority float64 `json:"startingpriority"` CurrentPriority float64 `json:"currentpriority"` Depends []string `json:"depends"` @@ -375,7 +351,7 @@ type TxRawResult struct { Vin []Vin `json:"vin"` Vout []Vout `json:"vout"` BlockHash string `json:"blockhash,omitempty"` - BlockHeight int32 `json:"blockheight"` + BlockHeight int64 `json:"blockheight"` BlockIndex uint32 `json:"blockindex"` Confirmations uint64 `json:"confirmations,omitempty"` Time int64 `json:"time,omitempty"` diff --git a/dcrjson/walletsvrcmds.go b/dcrjson/walletsvrcmds.go index a7cff29a..e3879660 100644 --- a/dcrjson/walletsvrcmds.go +++ b/dcrjson/walletsvrcmds.go @@ -233,15 +233,6 @@ func NewGetTransactionCmd(txHash string, includeWatchOnly *bool) *GetTransaction } } -// GetWalletInfoCmd defines the getwalletinfo JSON-RPC command. -type GetWalletInfoCmd struct{} - -// NewGetWalletInfoCmd returns a new instance which can be used to issue a -// getwalletinfo JSON-RPC command. -func NewGetWalletInfoCmd() *GetWalletInfoCmd { - return &GetWalletInfoCmd{} -} - // ImportPrivKeyCmd defines the importprivkey JSON-RPC command. type ImportPrivKeyCmd struct { PrivKey string @@ -656,7 +647,6 @@ func init() { MustRegisterCmd("getreceivedbyaddress", (*GetReceivedByAddressCmd)(nil), flags) MustRegisterCmd("gettransaction", (*GetTransactionCmd)(nil), flags) MustRegisterCmd("getwalletfee", (*GetWalletFeeCmd)(nil), flags) - MustRegisterCmd("getwalletinfo", (*GetWalletInfoCmd)(nil), flags) MustRegisterCmd("importprivkey", (*ImportPrivKeyCmd)(nil), flags) MustRegisterCmd("keypoolrefill", (*KeyPoolRefillCmd)(nil), flags) MustRegisterCmd("listaccounts", (*ListAccountsCmd)(nil), flags) diff --git a/dcrjson/walletsvrcmds_test.go b/dcrjson/walletsvrcmds_test.go index 7f56828c..f3446e23 100644 --- a/dcrjson/walletsvrcmds_test.go +++ b/dcrjson/walletsvrcmds_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2014 The dcrsuite developers +// Copyright (c) 2014 The btcsuite developers // Copyright (c) 2015 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -350,17 +350,6 @@ func TestWalletSvrCmds(t *testing.T) { IncludeWatchOnly: dcrjson.Bool(true), }, }, - { - name: "getwalletinfo", - newCmd: func() (interface{}, error) { - return dcrjson.NewCmd("getwalletinfo") - }, - staticCmd: func() interface{} { - return dcrjson.NewGetWalletInfoCmd() - }, - marshalled: `{"jsonrpc":"1.0","method":"getwalletinfo","params":[],"id":1}`, - unmarshalled: &dcrjson.GetWalletInfoCmd{}, - }, { name: "importprivkey", newCmd: func() (interface{}, error) { diff --git a/doc.go b/doc.go index 54fc2223..b5015578 100644 --- a/doc.go +++ b/doc.go @@ -83,8 +83,6 @@ Application Options: --limitfreerelay= Limit relay of transactions with no transaction fee to the given amount in thousands of bytes per minute (15) - --norelaypriority Do not require free or low-fee transactions to have - high priority for relaying --maxorphantx= Max number of orphan transactions to keep in memory (1000) --generate= Generate (mine) decreds using the CPU diff --git a/docs/code_contribution_guidelines.md b/docs/code_contribution_guidelines.md index a08f449b..762f28c4 100644 --- a/docs/code_contribution_guidelines.md +++ b/docs/code_contribution_guidelines.md @@ -6,7 +6,6 @@ 4.1. [Share Early, Share Often](#ShareEarly)
4.2. [Testing](#Testing)
4.3. [Code Documentation and Commenting](#CodeDocumentation)
-4.4. [Model Git Commit Messages](#ModelGitCommitMessages)
5. [Code Approval Process](#CodeApproval)
5.1 [Code Review](#CodeReview)
5.2 [Rework Code (if needed)](#CodeRework)
@@ -195,52 +194,6 @@ if amt < 5460 { but it was left as a magic number to show how much of a difference a good comment can make. - -### 4.4 Code Documentation and Commenting - -This project prefers to keep a clean commit history with well-formed commit -messages. This section illustrates a model commit message and provides a bit -of background for it. This content was originally created by Tim Pope and made -available on his website, however that website is no longer active, so it is -being provided here. - -Here’s a model Git commit message: - -``` -Short (50 chars or less) summary of changes - -More detailed explanatory text, if necessary. Wrap it to about 72 -characters or so. In some contexts, the first line is treated as the -subject of an email and the rest of the text as the body. The blank -line separating the summary from the body is critical (unless you omit -the body entirely); tools like rebase can get confused if you run the -two together. - -Write your commit message in the present tense: "Fix bug" and not "Fixed -bug." This convention matches up with commit messages generated by -commands like git merge and git revert. - -Further paragraphs come after blank lines. - -- Bullet points are okay, too -- Typically a hyphen or asterisk is used for the bullet, preceded by a - single space, with blank lines in between, but conventions vary here -- Use a hanging indent -``` - -Here are some of the reasons why wrapping your commit messages to 72 columns is -a good thing. - -- git log doesn’t do any special special wrapping of the commit messages. With - the default pager of less -S, this means your paragraphs flow far off the edge - of the screen, making them difficult to read. On an 80 column terminal, if we - subtract 4 columns for the indent on the left and 4 more for symmetry on the - right, we’re left with 72 columns. -- git format-patch --stdout converts a series of commits to a series of emails, - using the messages for the message body. Good email netiquette dictates we - wrap our plain text emails such that there’s room for a few levels of nested - reply indicators without overflow in an 80 column terminal. - ### 5. Code Approval Process diff --git a/docs/json_rpc_api.md b/docs/json_rpc_api.md index bb6e30da..f47d1edd 100644 --- a/docs/json_rpc_api.md +++ b/docs/json_rpc_api.md @@ -294,20 +294,6 @@ the method name for further details such as parameter and return information. [Return to Overview](#MethodOverview)
*** -
- -| | | -|---|---| -|Method|getblockheader| -|Parameters|1. block hash (string, required) - the hash of the block
2. verbose (boolean, optional, default=true) - specifies the block header is returned as a JSON object instead of a hex-encoded string| -|Description|Returns hex-encoded bytes of the serialized block header.| -|Returns (verbose=false)|`"data" (string) hex-encoded bytes of the serialized block`| -|Returns (verbose=true)|`{ (json object)`
  `"hash": "blockhash", (string) the hash of the block (same as provided)`
  `"confirmations": n, (numeric) the number of confirmations`
  `"height": n, (numeric) the height of the block in the block chain`
  `"version": n, (numeric) the block version`
  `"merkleroot": "hash", (string) root hash of the merkle tree`
  `"time": n, (numeric) the block time in seconds since 1 Jan 1970 GMT`
  `"nonce": n, (numeric) the block nonce`
  `"bits": n, (numeric) the bits which represent the block difficulty`
  `"difficulty": n.nn, (numeric) the proof-of-work difficulty as a multiple of the minimum difficulty`
  `"previousblockhash": "hash", (string) the hash of the previous block`
  `"nextblockhash": "hash", (string) the hash of the next block (only if there is one)`
`}`| -|Example Return (verbose=false)|`"0200000035ab154183570282ce9afc0b494c9fc6a3cfea05aa8c1add2ecc564900000000`
`38ba3d78e4500a5a7570dbe61960398add4410d278b21cd9708e6d9743f374d544fc0552`
`27f1001c29c1ea3b"`
**Newlines added for display purposes. The actual return does not contain newlines.**| -|Example Return (verbose=true)|`{`
  `"hash": "00000000009e2958c15ff9290d571bf9459e93b19765c6801ddeccadbb160a1e",`
  `"confirmations": 392076,`
  `"height": 100000,`
  `"version": 2,`
  `"merkleroot": "d574f343976d8e70d91cb278d21044dd8a396019e6db70755a0a50e4783dba38",`
  `"time": 1376123972,`
  `"nonce": 1005240617,`
  `"bits": "1c00f127",`
  `"difficulty": 271.75767393,`
  `"previousblockhash": "000000004956cc2edd1a8caa05eacfa3c69f4c490bfc9ace820257834115ab35",`
  `"nextblockhash": "0000000000629d100db387f37d0f37c51118f250fb0946310a8c37316cbc4028"`
`}`| -[Return to Overview](#MethodOverview)
- -***
| | | @@ -366,18 +352,6 @@ the method name for further details such as parameter and return information. |Example Return|`{`
  `"version": 70000`
  `"protocolversion": 70001, `
  `"blocks": 298963,`
  `"timeoffset": 0,`
  `"connections": 17,`
  `"proxy": "",`
  `"difficulty": 8000872135.97,`
  `"testnet": false,`
  `"relayfee": 0.00001,`
`}`| [Return to Overview](#MethodOverview)
-*** -
- -| | | -|---|---| -|Method|getmempoolinfo| -|Parameters|None| -|Description|Returns a JSON object containing mempool-related information.| -|Returns|`{ (json object)`
  `"bytes": n, (numeric) size in bytes of the mempool`
  `"size": n, (numeric) number of transactions in the mempool`
`}`| -Example Return|`{`
  `"bytes": 310768,`
  `"size": 157,`
`}`| -[Return to Overview](#MethodOverview)
- ***
@@ -696,7 +670,7 @@ user. Click the method name for further details such as parameter and return in |Parameters|1. username (string, required)
2. passphrase (string, required)| |Description|Authenticate the connection against the username and password configured for the RPC server.
Invoking any other method before authenticating with this command will close the connection.
NOTE: This is only required if an HTTP Authorization header is not being used.| |Returns|Success: Nothing
Failure: Nothing (websocket disconnected)| -[Return to Overview](#WSExtMethodOverview)
+[Return to Overview](#ExtensionRequestOverview)
*** @@ -709,7 +683,7 @@ user. Click the method name for further details such as parameter and return in |Parameters|None| |Description|Request notifications for whenever a block is connected or disconnected from the main (best) chain.
NOTE: If a client subscribes to both block and transaction (recvtx and redeemingtx) notifications, the blockconnected notification will be sent after all transaction notifications have been sent. This allows clients to know when all relevant transactions for a block have been received.| |Returns|Nothing| -[Return to Overview](#WSExtMethodOverview)
+[Return to Overview](#ExtensionRequestOverview)
***
@@ -721,7 +695,7 @@ user. Click the method name for further details such as parameter and return in |Parameters|None| |Description|Cancel sending notifications for whenever a block is connected or disconnected from the main (best) chain.| |Returns|Nothing| -[Return to Overview](#WSExtMethodOverview)
+[Return to Overview](#ExtensionRequestOverview)
*** @@ -734,7 +708,7 @@ user. Click the method name for further details such as parameter and return in |Parameters|1. Addresses (JSON array, required)
 `[ (json array of strings)`
  `"decredaddress", (string) the decred address`
  `...`
 `]`| |Description|Send a recvtx notification when a transaction added to mempool or appears in a newly-attached block contains a txout pkScript sending to any of the passed addresses. Matching outpoints are automatically registered for redeemingtx notifications.| |Returns|Nothing| -[Return to Overview](#WSExtMethodOverview)
+[Return to Overview](#ExtensionRequestOverview)
*** @@ -747,7 +721,7 @@ user. Click the method name for further details such as parameter and return in |Parameters|1. Addresses (JSON array, required)
 `[ (json array of strings)`
  `"decredaddress", (string) the decred address`
  `...`
 `]`| |Description|Cancel registered receive notifications for each passed address.| |Returns|Nothing| -[Return to Overview](#WSExtMethodOverview)
+[Return to Overview](#ExtensionRequestOverview)
*** @@ -760,7 +734,7 @@ user. Click the method name for further details such as parameter and return in |Parameters|1. Outpoints (JSON array, required)
 `[ (JSON array)`
  `{ (JSON object)`
   `"hash":"data", (string) the hex-encoded bytes of the outpoint hash`
   `"index":n (numeric) the txout index of the outpoint`
  `},`
  `...`
 `]`| |Description|Send a redeemingtx notification when a transaction spending an outpoint appears in mempool (if relayed to this dcrd instance) and when such a transaction first appears in a newly-attached block.| |Returns|Nothing| -[Return to Overview](#WSExtMethodOverview)
+[Return to Overview](#ExtensionRequestOverview)
*** @@ -773,7 +747,7 @@ user. Click the method name for further details such as parameter and return in |Parameters|1. Outpoints (JSON array, required)
 `[ (JSON array)`
  `{ (JSON object)`
   `"hash":"data", (string) the hex-encoded bytes of the outpoint hash`
   `"index":n (numeric) the txout index of the outpoint`
  `},`
  `...`
 `]`| |Description|Cancel registered spending notifications for each passed outpoint.| |Returns|Nothing| -[Return to Overview](#WSExtMethodOverview)
+[Return to Overview](#ExtensionRequestOverview)
*** @@ -786,7 +760,7 @@ user. Click the method name for further details such as parameter and return in |Parameters|1. BeginBlock (string, required) block hash to begin rescanning from
2. Addresses (JSON array, required)
 `[ (json array of strings)`
  `"decredaddress", (string) the decred address`
  `...`
 `]`
3. Outpoints (JSON array, required)
 `[ (JSON array)`
  `{ (JSON object)`
   `"hash":"data", (string) the hex-encoded bytes of the outpoint hash`
   `"index":n (numeric) the txout index of the outpoint`
  `},`
  `...`
 `]`
4. EndBlock (string, optional) hash of final block to rescan| |Description|Rescan block chain for transactions to addresses, starting at block BeginBlock and ending at EndBlock. The current known UTXO set for all passed addresses at height BeginBlock should included in the Outpoints argument. If EndBlock is omitted, the rescan continues through the best block in the main chain. Additionally, if no EndBlock is provided, the client is automatically registered for transaction notifications for all rescanned addresses and the final UTXO set. Rescan results are sent as recvtx and redeemingtx notifications. This call returns once the rescan completes.| |Returns|Nothing| -[Return to Overview](#WSExtMethodOverview)
+[Return to Overview](#ExtensionRequestOverview)
*** @@ -799,7 +773,7 @@ user. Click the method name for further details such as parameter and return in |Parameters|1. verbose (boolean, optional, default=false) - specifies which type of notification to receive. If verbose is true, then the caller receives [txacceptedverbose](#txacceptedverbose), otherwise the caller receives [txaccepted](#txaccepted)| |Description|Send either a [txaccepted](#txaccepted) or a [txacceptedverbose](#txacceptedverbose) notification when a new transaction is accepted into the mempool.| |Returns|Nothing| -[Return to Overview](#WSExtMethodOverview)
+[Return to Overview](#ExtensionRequestOverview)
*** diff --git a/mempool.go b/mempool.go index b496b4da..6c999117 100644 --- a/mempool.go +++ b/mempool.go @@ -117,7 +117,7 @@ type TxDesc struct { Tx *dcrutil.Tx // Transaction. Type stake.TxType // Transcation type. Added time.Time // Time when added to pool. - Height int32 // Blockheight when added to pool. + Height int64 // Blockheight when added to pool. Fee int64 // Transaction fees. startingPriority float64 // Priority when added to the pool. } @@ -398,11 +398,6 @@ func (mp *txMemPool) SortParentsByVotes(currentTopBlock chainhash.Hash, // relay fee. In particular, if the cost to the network to spend coins is more // than 1/3 of the minimum transaction relay fee, it is considered dust. func isDust(txOut *wire.TxOut, params *chaincfg.Params) bool { - // Unspendable outputs are considered dust. - if txscript.IsUnspendable(txOut.PkScript) { - return true - } - // The total serialized size consists of the output and the associated // input script to redeem it. Since there is no input script // to redeem it yet, use the minimum size of a typical input script. @@ -544,7 +539,7 @@ func checkPkScriptStandard(version uint16, pkScript []byte, // of recognized forms, and not containing "dust" outputs (those that are // so small it costs more to process them than they are worth). func (mp *txMemPool) checkTransactionStandard(tx *dcrutil.Tx, txType stake.TxType, - height int32) error { + height int64) error { msgTx := tx.MsgTx() // The transaction must be a currently supported version. @@ -1034,7 +1029,7 @@ func (mp *txMemPool) RemoveDoubleSpends(tx *dcrutil.Tx) { func (mp *txMemPool) addTransaction( tx *dcrutil.Tx, txType stake.TxType, - height int32, + height, fee int64) { // Add the transaction to the pool and mark the referenced outpoints // as spent by the pool. @@ -1176,7 +1171,7 @@ func (mp *txMemPool) FindTxForAddr(addr dcrutil.Address) []*dcrutil.Tx { // which are currently in the mempool and hence not mined into a block yet, // contribute no additional input age to the transaction. func calcInputValueAge(txDesc *TxDesc, txStore blockchain.TxStore, - nextBlockHeight int32) float64 { + nextBlockHeight int64) float64 { var totalInputAge float64 for _, txIn := range txDesc.Tx.MsgTx().TxIn { originHash := &txIn.PreviousOutPoint.Hash @@ -1189,7 +1184,7 @@ func calcInputValueAge(txDesc *TxDesc, txStore blockchain.TxStore, // have their block height set to a special constant. // Their input age should computed as zero since their // parent hasn't made it into a block yet. - var inputAge int32 + var inputAge int64 if txData.BlockHeight == mempoolHeight { inputAge = 0 } else { @@ -1199,7 +1194,7 @@ func calcInputValueAge(txDesc *TxDesc, txStore blockchain.TxStore, // Sum the input value times age. originTxOut := txData.Tx.MsgTx().TxOut[originIndex] inputValue := originTxOut.Value - totalInputAge += float64(inputValue * int64(inputAge)) + totalInputAge += float64(inputValue * inputAge) } } @@ -1273,7 +1268,7 @@ func (td *TxDesc) StartingPriority(txStore blockchain.TxStore) float64 { // CurrentPriority calculates the current priority of this tx descriptor's // underlying transaction relative to the next block height. func (td *TxDesc) CurrentPriority(txStore blockchain.TxStore, - nextBlockHeight int32) float64 { + nextBlockHeight int64) float64 { inputAge := calcInputValueAge(td, txStore, nextBlockHeight) return calcPriority(td.Tx, inputAge) } @@ -1919,7 +1914,7 @@ func (mp *txMemPool) processOrphans(hash *chainhash.Hash) { // stake difficulty is below the current required stake difficulty should be // pruned from mempool since they will never be mined. The same idea stands // for SSGen and SSRtx -func (mp *txMemPool) PruneStakeTx(requiredStakeDifficulty int64, height int32) { +func (mp *txMemPool) PruneStakeTx(requiredStakeDifficulty, height int64) { // Protect concurrent access. mp.Lock() defer mp.Unlock() @@ -1927,11 +1922,11 @@ func (mp *txMemPool) PruneStakeTx(requiredStakeDifficulty int64, height int32) { mp.pruneStakeTx(requiredStakeDifficulty, height) } -func (mp *txMemPool) pruneStakeTx(requiredStakeDifficulty int64, height int32) { +func (mp *txMemPool) pruneStakeTx(requiredStakeDifficulty, height int64) { for _, tx := range mp.pool { txType := detectTxType(tx.Tx) if txType == stake.TxTypeSStx && - tx.Height+int32(heightDiffToPruneTicket) < height { + tx.Height+int64(heightDiffToPruneTicket) < height { mp.removeTransaction(tx.Tx, true) } if txType == stake.TxTypeSStx && @@ -1939,7 +1934,7 @@ func (mp *txMemPool) pruneStakeTx(requiredStakeDifficulty int64, height int32) { mp.removeTransaction(tx.Tx, true) } if (txType == stake.TxTypeSSRtx || txType == stake.TxTypeSSGen) && - tx.Height+int32(heightDiffToPruneVotes) < height { + tx.Height+int64(heightDiffToPruneVotes) < height { mp.removeTransaction(tx.Tx, true) } } @@ -1947,7 +1942,7 @@ func (mp *txMemPool) pruneStakeTx(requiredStakeDifficulty int64, height int32) { // PruneExpiredTx prunes expired transactions from the mempool that may no longer // be able to be included into a block. -func (mp *txMemPool) PruneExpiredTx(height int32) { +func (mp *txMemPool) PruneExpiredTx(height int64) { // Protect concurrent access. mp.Lock() defer mp.Unlock() @@ -1955,10 +1950,10 @@ func (mp *txMemPool) PruneExpiredTx(height int32) { mp.pruneExpiredTx(height) } -func (mp *txMemPool) pruneExpiredTx(height int32) { +func (mp *txMemPool) pruneExpiredTx(height int64) { for _, tx := range mp.pool { if tx.Tx.MsgTx().Expiry != 0 { - if height >= int32(tx.Tx.MsgTx().Expiry) { + if height >= int64(tx.Tx.MsgTx().Expiry) { txmpLog.Debugf("Pruning expired transaction %v from the "+ "mempool", tx.Tx.Sha()) mp.removeTransaction(tx.Tx, true) diff --git a/mining.go b/mining.go index a4453a3a..d4c35786 100644 --- a/mining.go +++ b/mining.go @@ -170,7 +170,7 @@ type BlockTemplate struct { block *wire.MsgBlock fees []int64 sigOpCounts []int64 - height int32 + height int64 validPayAddress bool } @@ -286,7 +286,7 @@ func getCoinbaseExtranonces(msgBlock *wire.MsgBlock) []uint64 { // block by regenerating the coinbase script with the passed value and block // height. It also recalculates and updates the new merkle root that results // from changing the coinbase script. -func UpdateExtraNonce(msgBlock *wire.MsgBlock, blockHeight int32, +func UpdateExtraNonce(msgBlock *wire.MsgBlock, blockHeight int64, extraNonces []uint64) error { // First block has no extranonce. if blockHeight == 1 { @@ -322,7 +322,7 @@ func UpdateExtraNonce(msgBlock *wire.MsgBlock, blockHeight int32, // address handling is useful. func createCoinbaseTx(coinbaseScript []byte, opReturnPkScript []byte, - nextBlockHeight int32, + nextBlockHeight int64, addr dcrutil.Address, voters uint16, params *chaincfg.Params) (*dcrutil.Tx, error) { @@ -443,7 +443,7 @@ func createCoinbaseTx(coinbaseScript []byte, // to the passed transaction as spent. It also adds the passed transaction to // the store at the provided height. func spendTransaction(txStore blockchain.TxStore, tx *dcrutil.Tx, - height int32) error { + height int64) error { for _, txIn := range tx.MsgTx().TxIn { originHash := &txIn.PreviousOutPoint.Hash originIndex := txIn.PreviousOutPoint.Index @@ -647,7 +647,7 @@ func deepCopyBlockTemplate(blockTemplate *BlockTemplate) *BlockTemplate { // work off of is present, it will return a copy of that template to pass to the // miner. // Safe for concurrent access. -func handleTooFewVoters(nextHeight int32, +func handleTooFewVoters(nextHeight int64, miningAddress dcrutil.Address, bm *blockManager) (*BlockTemplate, error) { timeSource := bm.server.timeSource @@ -822,7 +822,7 @@ func handleTooFewVoters(nextHeight int32, block: btMsgBlock, fees: []int64{0}, sigOpCounts: []int64{0}, - height: int32(topBlock.MsgBlock().Header.Height), + height: int64(topBlock.MsgBlock().Header.Height), validPayAddress: miningAddress != nil, } @@ -1171,7 +1171,7 @@ mempoolLoop: } if !((blockHash == *prevHash) && - (int32(blockHeight) == nextBlockHeight-1)) { + (int64(blockHeight) == nextBlockHeight-1)) { minrLog.Tracef("Skipping ssgen tx %s because it does "+ "not vote on the correct block", tx.Sha()) continue @@ -1255,7 +1255,7 @@ mempoolLoop: originTxOut := txData.Tx.MsgTx().TxOut[originIndex] inputValue := originTxOut.Value inputAge := nextBlockHeight - txData.BlockHeight - inputValueAge += float64(inputValue * int64(inputAge)) + inputValueAge += float64(inputValue * inputAge) } // Calculate the final transaction priority using the input diff --git a/peer.go b/peer.go index af1b344b..0038d869 100644 --- a/peer.go +++ b/peer.go @@ -60,17 +60,6 @@ const ( // queueEmptyFrequency is the frequency for the emptying of the queue. queueEmptyFrequency = 500 * time.Millisecond - - // connectionRetryInterval is the base amount of time to wait in between - // retries when connecting to persistent peers. It is adjusted by the - // number of retries such that there is a retry backoff. - connectionRetryInterval = time.Second * 10 - - // maxConnectionRetryInterval is the max amount of time retrying of a - // persistent peer is allowed to grow to. This is necessary since the - // retry logic uses a backoff mechanism which increases the interval - // base done the number of retries that have been done. - maxConnectionRetryInterval = time.Minute * 5 ) var ( @@ -606,8 +595,28 @@ func (p *peer) pushMerkleBlockMsg(sha *chainhash.Hash, doneChan, waitChan chan s } // Generate a merkle block by filtering the requested block according - // to the filter for the peer. - merkle, matchedTxIndices := bloom.NewMerkleBlock(blk, p.filter) + // to the filter for the peer and fetch any matched transactions from + // the database. + merkle, matchedHashes := bloom.NewMerkleBlock(blk, p.filter) + txList := p.server.db.FetchTxByShaList(matchedHashes) + + // Warn on any missing transactions which should not happen since the + // matched transactions come from an existing block. Also, find the + // final valid transaction index for later. + finalValidTxIndex := -1 + for i, txR := range txList { + if txR.Err != nil || txR.Tx == nil { + warnMsg := fmt.Sprintf("Failed to fetch transaction "+ + "%v which was matched by merkle block %v", + txR.Sha, sha) + if txR.Err != nil { + warnMsg += ": " + err.Error() + } + peerLog.Warnf(warnMsg) + continue + } + finalValidTxIndex = i + } // Once we have fetched data wait for any previous operation to finish. if waitChan != nil { @@ -617,21 +626,20 @@ func (p *peer) pushMerkleBlockMsg(sha *chainhash.Hash, doneChan, waitChan chan s // Send the merkleblock. Only send the done channel with this message // if no transactions will be sent afterwards. var dc chan struct{} - if len(matchedTxIndices) == 0 { + if finalValidTxIndex == -1 { dc = doneChan } p.QueueMessage(merkle, dc) // Finally, send any matched transactions. - blkTransactions := blk.MsgBlock().Transactions - for i, txIndex := range matchedTxIndices { + for i, txR := range txList { // Only send the done channel on the final transaction. var dc chan struct{} - if i == len(matchedTxIndices)-1 { + if i == finalValidTxIndex { dc = doneChan } - if txIndex < uint32(len(blkTransactions)) { - p.QueueMessage(blkTransactions[txIndex], dc) + if txR.Err == nil && txR.Tx != nil { + p.QueueMessage(txR.Tx, dc) } } @@ -1066,7 +1074,7 @@ func (p *peer) handleGetBlocksMsg(msg *wire.MsgGetBlocks) { // provided locator are known. This does mean the client will start // over with the genesis block if unknown block locators are provided. // This mirrors the behavior in the reference implementation. - startIdx := int32(1) + startIdx := int64(1) for _, hash := range msg.BlockLocatorHashes { height, err := p.server.db.FetchBlockHeightBySha(hash) if err == nil { @@ -1110,7 +1118,7 @@ func (p *peer) handleGetBlocksMsg(msg *wire.MsgGetBlocks) { iv := wire.NewInvVect(wire.InvTypeBlock, &hashCopy) invMsg.AddInvVect(iv) } - start += int32(len(hashList)) + start += int64(len(hashList)) } // Send the inventory message if there is anything to send. @@ -1131,11 +1139,6 @@ func (p *peer) handleGetBlocksMsg(msg *wire.MsgGetBlocks) { // handleGetHeadersMsg is invoked when a peer receives a getheaders decred // message. func (p *peer) handleGetHeadersMsg(msg *wire.MsgGetHeaders) { - // Ignore getheaders requests if not in sync. - if !p.server.blockManager.IsCurrent() { - return - } - // Attempt to look up the height of the provided stop hash. endIdx := database.AllShas height, err := p.server.db.FetchBlockHeightBySha(&msg.HashStop) @@ -1172,7 +1175,7 @@ func (p *peer) handleGetHeadersMsg(msg *wire.MsgGetHeaders) { // provided locator are known. This does mean the client will start // over with the genesis block if unknown block locators are provided. // This mirrors the behavior in the reference implementation. - startIdx := int32(1) + startIdx := int64(1) for _, hash := range msg.BlockLocatorHashes { height, err := p.server.db.FetchBlockHeightBySha(hash) if err == nil { @@ -1221,7 +1224,7 @@ func (p *peer) handleGetHeadersMsg(msg *wire.MsgGetHeaders) { // Start at the next block header after the latest one on the // next loop iteration. - start += int32(len(hashList)) + start += int64(len(hashList)) } p.QueueMessage(headersMsg, nil) } @@ -1771,7 +1774,7 @@ out: // Create and send as many inv messages as needed to // drain the inventory send queue. - invMsg := wire.NewMsgInvSizeHint(uint(invSendQueue.Len())) + invMsg := wire.NewMsgInv() for e := invSendQueue.Front(); e != nil; e = invSendQueue.Front() { iv := invSendQueue.Remove(e).(*wire.InvVect) @@ -1786,7 +1789,7 @@ out: waiting = queuePacket( outMsg{msg: invMsg}, pendingMsgs, waiting) - invMsg = wire.NewMsgInvSizeHint(uint(invSendQueue.Len())) + invMsg = wire.NewMsgInv() } // Add the inventory that is being relayed to @@ -2114,9 +2117,6 @@ func newOutboundPeer(s *server, addr string, persistent bool, retryCount int64) if p.retryCount > 0 { scaledInterval := connectionRetryInterval.Nanoseconds() * p.retryCount / 2 scaledDuration := time.Duration(scaledInterval) - if scaledDuration > maxConnectionRetryInterval { - scaledDuration = maxConnectionRetryInterval - } srvrLog.Debugf("Retrying connection to %s in %s", addr, scaledDuration) time.Sleep(scaledDuration) } diff --git a/rpcserver.go b/rpcserver.go index a1fdf548..ee07f79b 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -165,7 +165,6 @@ var rpcHandlersBeforeInit = map[string]commandHandler{ "getblock": handleGetBlock, "getblockcount": handleGetBlockCount, "getblockhash": handleGetBlockHash, - "getblockheader": handleGetBlockHeader, "getblocktemplate": handleGetBlockTemplate, "getcoinsupply": handleGetCoinSupply, "getconnectioncount": handleGetConnectionCount, @@ -174,7 +173,6 @@ var rpcHandlersBeforeInit = map[string]commandHandler{ "getgenerate": handleGetGenerate, "gethashespersec": handleGetHashesPerSec, "getinfo": handleGetInfo, - "getmempoolinfo": handleGetMempoolInfo, "getmininginfo": handleGetMiningInfo, "getnettotals": handleGetNetTotals, "getnetworkhashps": handleGetNetworkHashPS, @@ -1256,9 +1254,10 @@ func handleDebugLevel(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) // createVinList returns a slice of JSON objects for the inputs of the passed // transaction. func createVinList(mtx *wire.MsgTx) []dcrjson.Vin { + tx := dcrutil.NewTx(mtx) vinList := make([]dcrjson.Vin, len(mtx.TxIn)) for i, v := range mtx.TxIn { - if blockchain.IsCoinBaseTx(mtx) { + if blockchain.IsCoinBase(tx) { vinList[i].Coinbase = hex.EncodeToString(v.SignatureScript) } else { vinList[i].Txid = v.PreviousOutPoint.Hash.String() @@ -1288,7 +1287,7 @@ func createVoutList(mtx *wire.MsgTx, chainParams *chaincfg.Params) []dcrjson.Vou voutList := make([]dcrjson.Vout, len(mtx.TxOut)) for i, v := range mtx.TxOut { voutList[i].N = uint32(i) - voutList[i].Value = dcrutil.Amount(v.Value).ToCoin() + voutList[i].Value = float64(v.Value) / dcrutil.AtomsPerCoin voutList[i].Version = v.Version // The disassembled string will contain [error] inline if the @@ -1320,9 +1319,10 @@ func createVoutList(mtx *wire.MsgTx, chainParams *chaincfg.Params) []dcrjson.Vou // createTxRawResult converts the passed transaction and associated parameters // to a raw transaction JSON object. -func createTxRawResult(chainParams *chaincfg.Params, mtx *wire.MsgTx, - txHash string, blkHeader *wire.BlockHeader, blkHash string, - blkHeight int32, blkIdx uint32, chainHeight int32) (*dcrjson.TxRawResult, error) { +func createTxRawResult(chainParams *chaincfg.Params, txHash string, + mtx *wire.MsgTx, blk *dcrutil.Block, maxIdx int64, + blkHash *chainhash.Hash, blkHeight int64, + blkIdx uint32) (*dcrjson.TxRawResult, error) { mtxHex, err := messageToHex(mtx) if err != nil { @@ -1341,12 +1341,15 @@ func createTxRawResult(chainParams *chaincfg.Params, mtx *wire.MsgTx, BlockIndex: blkIdx, } - if blkHeader != nil { + if blk != nil { + blockHeader := &blk.MsgBlock().Header + idx := blk.Height() + // This is not a typo, they are identical in bitcoind as well. - txReply.Time = blkHeader.Timestamp.Unix() - txReply.Blocktime = blkHeader.Timestamp.Unix() - txReply.BlockHash = blkHash - txReply.Confirmations = uint64(1 + chainHeight - blkHeight) + txReply.Time = blockHeader.Timestamp.Unix() + txReply.Blocktime = blockHeader.Timestamp.Unix() + txReply.BlockHash = blkHash.String() + txReply.Confirmations = uint64(1 + maxIdx - idx) } return txReply, nil @@ -1870,8 +1873,8 @@ func handleGetBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i Revocations: blockHeader.Revocations, PoolSize: blockHeader.PoolSize, Time: blockHeader.Timestamp.Unix(), - Confirmations: uint32(1 + maxIdx - idx), - Height: int32(idx), + Confirmations: uint64(1 + maxIdx - idx), + Height: idx, Size: int32(len(buf)), Bits: strconv.FormatInt(int64(blockHeader.Bits), 16), SBits: sbitsFloat, @@ -1899,9 +1902,11 @@ func handleGetBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i txns := blk.Transactions() rawTxns := make([]dcrjson.TxRawResult, len(txns)) for i, tx := range txns { + txHash := tx.Sha().String() + mtx := tx.MsgTx() + rawTxn, err := createTxRawResult(s.server.chainParams, - tx.MsgTx(), tx.Sha().String(), blockHeader, - sha.String(), idx, uint32(i), maxIdx) + txHash, mtx, blk, maxIdx, sha, blk.Height(), uint32(i)) if err != nil { return nil, err } @@ -1912,10 +1917,11 @@ func handleGetBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i stxns := blk.STransactions() rawSTxns := make([]dcrjson.TxRawResult, len(stxns)) for i, tx := range stxns { - rawSTxn, err := createTxRawResult(s.server.chainParams, - tx.MsgTx(), tx.Sha().String(), blockHeader, - sha.String(), idx, uint32(i), maxIdx) + txHash := tx.Sha().String() + mtx := tx.MsgTx() + rawSTxn, err := createTxRawResult(s.server.chainParams, + txHash, mtx, blk, maxIdx, sha, blk.Height(), uint32(i)) if err != nil { return nil, err } @@ -1927,7 +1933,7 @@ func handleGetBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i // Get next block unless we are already at the top. if idx < maxIdx && idx >= 0 { var shaNext *chainhash.Hash - shaNext, err = s.server.db.FetchBlockShaByHeight(idx + 1) + shaNext, err = s.server.db.FetchBlockShaByHeight(int64(idx + 1)) if err != nil { context := "No next block" return nil, internalRPCError(err.Error(), context) @@ -1955,7 +1961,7 @@ func handleGetBlockCount(s *rpcServer, cmd interface{}, closeChan <-chan struct{ // handleGetBlockHash implements the getblockhash command. func handleGetBlockHash(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) { c := cmd.(*dcrjson.GetBlockHashCmd) - sha, err := s.server.db.FetchBlockShaByHeight(int32(c.Index)) + sha, err := s.server.db.FetchBlockShaByHeight(c.Index) if err != nil { return nil, &dcrjson.RPCError{ Code: dcrjson.ErrRPCOutOfRange, @@ -1966,71 +1972,6 @@ func handleGetBlockHash(s *rpcServer, cmd interface{}, closeChan <-chan struct{} return sha.String(), nil } -// handleGetBlockHeader implements the getblockheader command. -func handleGetBlockHeader(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) { - c := cmd.(*dcrjson.GetBlockHeaderCmd) - - sha, err := chainhash.NewHashFromStr(c.Hash) - if err != nil { - return nil, err - } - - if c.Verbose == nil || *c.Verbose { - blk, err := s.server.db.FetchBlockBySha(sha) - if err != nil { - return nil, &dcrjson.RPCError{ - Code: dcrjson.ErrRPCInvalidAddressOrKey, - Message: "Invalid address or key: " + err.Error(), - } - } - - _, maxIdx, err := s.server.db.NewestSha() - if err != nil { - context := "Failed to get newest hash" - return nil, internalRPCError(err.Error(), context) - } - - var shaNextStr string - shaNext, err := s.server.db.FetchBlockShaByHeight(blk.Height() + 1) - if err == nil { - shaNextStr = shaNext.String() - } - - msgBlock := blk.MsgBlock() - blockHeaderReply := dcrjson.GetBlockHeaderVerboseResult{ - Hash: c.Hash, - Confirmations: uint32(1 + maxIdx - blk.Height()), - Height: int32(blk.Height()), - Version: msgBlock.Header.Version, - MerkleRoot: msgBlock.Header.MerkleRoot.String(), - NextHash: shaNextStr, - PreviousHash: msgBlock.Header.PrevBlock.String(), - Nonce: uint64(msgBlock.Header.Nonce), - Time: msgBlock.Header.Timestamp.Unix(), - Bits: strconv.FormatInt(int64(msgBlock.Header.Bits), 16), - Difficulty: getDifficultyRatio(msgBlock.Header.Bits), - } - return blockHeaderReply, nil - } - - // Verbose disabled - blkHeader, err := s.server.db.FetchBlockHeaderBySha(sha) - if err != nil { - return nil, &dcrjson.RPCError{ - Code: dcrjson.ErrRPCInvalidAddressOrKey, - Message: "Invalid address or key: " + err.Error(), - } - } - - buf := bytes.NewBuffer(make([]byte, 0, wire.MaxBlockHeaderPayload)) - if err = blkHeader.BtcEncode(buf, maxProtocolVersion); err != nil { - errStr := fmt.Sprintf("Failed to serialize data: %v", err) - return nil, internalRPCError(errStr, "") - } - - return hex.EncodeToString(buf.Bytes()), nil -} - // encodeTemplateID encodes the passed details into an ID that can be used to // uniquely identify a block template. func encodeTemplateID(prevHash *chainhash.Hash, lastGenerated time.Time) string { @@ -2436,7 +2377,7 @@ func (state *gbtWorkState) blockTemplateResult(bm *blockManager, } fee, err = blockchain.CheckTransactionInputs(txU, - int32(template.block.Header.Height), + int64(template.block.Header.Height), store, true, // Ensure fraud proofs are correct bm.server.chainParams) @@ -2551,7 +2492,7 @@ func (state *gbtWorkState) blockTemplateResult(bm *blockManager, } fee, err = blockchain.CheckTransactionInputs(txU, - int32(template.block.Header.Height), + int64(template.block.Header.Height), store, true, // Ensure fraud proofs are correct bm.server.chainParams) @@ -3057,7 +2998,7 @@ func handleGetCoinSupply(s *rpcServer, cmd interface{}, closeChan <-chan struct{ return s.coinSupplyTotal, nil } - for i := 0; int32(i) < tipHeight+1; i++ { + for i := 0; int64(i) < tipHeight+1; i++ { if i == 0 { continue } @@ -3070,7 +3011,7 @@ func handleGetCoinSupply(s *rpcServer, cmd interface{}, closeChan <-chan struct{ base *= params.MulSubsidy base /= params.DivSubsidy } - blockSha, err := s.server.db.FetchBlockShaByHeight(int32(i)) + blockSha, err := s.server.db.FetchBlockShaByHeight(int64(i)) if err != nil { context := "Failed to get block sha by height" return nil, internalRPCError(err.Error(), context) @@ -3089,7 +3030,7 @@ func handleGetCoinSupply(s *rpcServer, cmd interface{}, closeChan <-chan struct{ tax := ((base * int64(params.BlockTaxProportion)) / int64(params.TotalSubsidyProportions())) - if int32(i) < params.StakeValidationHeight { + if int64(i) < params.StakeValidationHeight { supply += (work + tax) } else { // Make sure to reduce work and tax subsidy based on number of voters @@ -3185,23 +3126,6 @@ func handleGetInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (in return ret, nil } -// handleGetMempoolInfo implements the getmempoolinfo command. -func handleGetMempoolInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) { - txD := s.server.txMemPool.TxDescs() - - var numBytes int64 - for _, desc := range txD { - numBytes += int64(desc.Tx.MsgTx().SerializeSize()) - } - - ret := &dcrjson.GetMempoolInfoResult{ - Size: int64(len(txD)), - Bytes: numBytes, - } - - return ret, nil -} - // handleGetMiningInfo implements the getmininginfo command. We only return the // fields that are not related to wallet functionality. func handleGetMiningInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) { @@ -3238,7 +3162,7 @@ func handleGetMiningInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{ } result := dcrjson.GetMiningInfoResult{ - Blocks: int64(height), + Blocks: height, CurrentBlockSize: uint64(len(blockBytes)), CurrentBlockTx: uint64(len(block.MsgBlock().Transactions)), Difficulty: getDifficultyRatio(block.MsgBlock().Header.Bits), @@ -3282,9 +3206,9 @@ func handleGetNetworkHashPS(s *rpcServer, cmd interface{}, closeChan <-chan stru // since we can't reasonably calculate the number of network hashes // per second from invalid values. When it's negative, use the current // best block height. - endHeight := int32(-1) + endHeight := int64(-1) if c.Height != nil { - endHeight = int32(*c.Height) + endHeight = int64(*c.Height) } if endHeight > newestHeight || endHeight == 0 { return int64(0), nil @@ -3299,15 +3223,15 @@ func handleGetNetworkHashPS(s *rpcServer, cmd interface{}, closeChan <-chan stru // starting height is not before the beginning of the chain. // Decred TODO: Make sure this blocksPerRetarget value is accurate - blocksPerRetarget := int32(s.server.chainParams.TargetTimespan / + blocksPerRetarget := int64(s.server.chainParams.TargetTimespan / s.server.chainParams.TimePerBlock) - numBlocks := int32(120) + numBlocks := int64(120) if c.Blocks != nil { - numBlocks = int32(*c.Blocks) + numBlocks = int64(*c.Blocks) } - var startHeight int32 + var startHeight int64 if numBlocks <= 0 { startHeight = endHeight - ((endHeight % blocksPerRetarget) + 1) } else { @@ -3428,7 +3352,7 @@ func handleGetRawMempool(s *rpcServer, cmd interface{}, closeChan <-chan struct{ Size: int32(desc.Tx.MsgTx().SerializeSize()), Fee: dcrutil.Amount(desc.Fee).ToCoin(), Time: desc.Added.Unix(), - Height: int32(desc.Height), + Height: desc.Height, StartingPriority: startingPriority, CurrentPriority: currentPriority, Depends: make([]string, 0), @@ -3494,11 +3418,13 @@ func handleGetRawTransaction(s *rpcServer, cmd interface{}, closeChan <-chan str // Try to fetch the transaction from the memory pool and if that fails, // try the block database. + var maxIdx int64 var mtx *wire.MsgTx var blkHash *chainhash.Hash - var blkHeight int32 + var blkHeight int64 var blkIndex uint32 var tip *dcrutil.Block + needsVotes := false tx, err := s.server.txMemPool.FetchTransaction(txHash) if err != nil { // Search the database. @@ -3520,6 +3446,7 @@ func handleGetRawTransaction(s *rpcServer, cmd interface{}, closeChan <-chan str blkHash = tip.Sha() blkHeight = tip.Height() blkIndex = uint32(i) + needsVotes = true } } @@ -3542,6 +3469,12 @@ func handleGetRawTransaction(s *rpcServer, cmd interface{}, closeChan <-chan str mtx = tx.MsgTx() } + _, maxIdx, err = s.server.db.NewestSha() + if err != nil { + context := "Failed to get newest hash" + return nil, internalRPCError(err.Error(), context) + } + // When the verbose flag isn't set, simply return the network-serialized // transaction as a hex-encoded string. if c.Verbose == nil || *c.Verbose == 0 { @@ -3556,30 +3489,24 @@ func handleGetRawTransaction(s *rpcServer, cmd interface{}, closeChan <-chan str return mtxHex, nil } - var blkHeader *wire.BlockHeader - var blkHashStr string - var chainHeight int32 + var blk *dcrutil.Block if blkHash != nil { - blkHeader, err = s.server.db.FetchBlockHeaderBySha(blkHash) - if err != nil { - rpcsLog.Errorf("Error fetching sha: %v", err) - return nil, &dcrjson.RPCError{ - Code: dcrjson.ErrRPCBlockNotFound, - Message: "Block not found: " + err.Error(), + if needsVotes { + blk = tip + } else { + blk, err = s.server.db.FetchBlockBySha(blkHash) + if err != nil { + rpcsLog.Errorf("Error fetching sha: %v", err) + return nil, &dcrjson.RPCError{ + Code: dcrjson.ErrRPCBlockNotFound, + Message: "Block not found: " + err.Error(), + } } } - - _, chainHeight, err = s.server.db.NewestSha() - if err != nil { - context := "Failed to get newest hash" - return nil, internalRPCError(err.Error(), context) - } - - blkHashStr = blkHash.String() } - rawTxn, err := createTxRawResult(s.server.chainParams, mtx, - txHash.String(), blkHeader, blkHashStr, blkHeight, blkIndex, chainHeight) + rawTxn, err := createTxRawResult(s.server.chainParams, c.Txid, mtx, blk, + maxIdx, blkHash, blkHeight, blkIndex) if err != nil { return nil, err } @@ -3658,7 +3585,7 @@ func handleGetTxOut(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i // from there, otherwise attempt to fetch from the block database. var mtx *wire.MsgTx var bestBlockSha string - var confirmations int32 + var confirmations int64 var dbSpentInfo []bool includeMempool := true if c.IncludeMempool != nil { @@ -3744,7 +3671,7 @@ func handleGetTxOut(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i txOutReply := &dcrjson.GetTxOutResult{ BestBlock: bestBlockSha, - Confirmations: int64(confirmations), + Confirmations: confirmations, Value: dcrutil.Amount(txOut.Value).ToUnit(dcrutil.AmountCoin), Version: mtx.Version, ScriptPubKey: dcrjson.ScriptPubKeyResult{ @@ -3761,10 +3688,10 @@ func handleGetTxOut(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i // pruneOldBlockTemplates prunes all old block templates from the templatePool // map. Must be called with the RPC workstate locked to avoid races to the map. -func pruneOldBlockTemplates(s *rpcServer, bestHeight int32) { +func pruneOldBlockTemplates(s *rpcServer, bestHeight int64) { pool := s.templatePool for rootHash, blkData := range pool { - height := int32(blkData.msgBlock.Header.Height) + height := int64(blkData.msgBlock.Header.Height) if height < bestHeight-getworkExpirationDiff { delete(pool, rootHash) } @@ -4354,11 +4281,9 @@ func handleSearchRawTransactions(s *rpcServer, cmd interface{}, // within a block. So we conditionally fetch a txs // embedded block here. This will be reflected in the // final JSON output (mempool won't have confirmations). - var blkHeader *wire.BlockHeader - var blkHashStr string - var blkHeight int32 + var blk *dcrutil.Block if txReply.BlkSha != nil { - blkHeader, err = s.server.db.FetchBlockHeaderBySha(txReply.BlkSha) + blk, err = s.server.db.FetchBlockBySha(txReply.BlkSha) if err != nil { rpcsLog.Errorf("Error fetching sha: %v", err) return nil, &dcrjson.RPCError{ @@ -4366,20 +4291,14 @@ func handleSearchRawTransactions(s *rpcServer, cmd interface{}, Message: "Block not found", } } - blkHashStr = txReply.BlkSha.String() - blkHeight = txReply.Height } + var blkHash *chainhash.Hash + var blkHeight int64 var blkIndex uint32 - blk, err := s.server.db.FetchBlockBySha(txReply.BlkSha) - if err != nil { - rpcsLog.Errorf("Error fetching sha: %v", err) - return nil, &dcrjson.RPCError{ - Code: dcrjson.ErrRPCBlockNotFound, - Message: "Block not found", - } - } if blk != nil { + blkHash = blk.Sha() + blkHeight = blk.Height() blkIndex = wire.NullBlockIndex for i, tx := range blk.Transactions() { @@ -4389,9 +4308,8 @@ func handleSearchRawTransactions(s *rpcServer, cmd interface{}, } } - rawTxn, err := createTxRawResult(s.server.chainParams, mtx, - txHash, blkHeader, blkHashStr, blkHeight, blkIndex, maxIdx) - + rawTxn, err := createTxRawResult(s.server.chainParams, + txHash, mtx, blk, maxIdx, blkHash, blkHeight, blkIndex) if err != nil { return nil, err } @@ -4585,7 +4503,7 @@ func verifyChain(db database.Db, level, depth int32, timeSource blockchain.Media for height := curHeight; height > finishHeight; height-- { // Level 0 just looks up the block. - sha, err := db.FetchBlockShaByHeight(height) + sha, err := db.FetchBlockShaByHeight(int64(height)) if err != nil { rpcsLog.Errorf("Verify is unable to fetch block at "+ "height %d: %v", height, err) @@ -4716,7 +4634,7 @@ type rpcServer struct { // coin supply caching values coinSupplyMtx sync.Mutex - coinSupplyHeight int32 + coinSupplyHeight int64 coinSupplyTotal int64 } diff --git a/rpcserverhelp.go b/rpcserverhelp.go index db54cad9..8d5091da 100644 --- a/rpcserverhelp.go +++ b/rpcserverhelp.go @@ -260,27 +260,6 @@ var helpDescsEnUS = map[string]string{ "getblockhash-index": "The block height", "getblockhash--result0": "The block hash", - // GetBlockHeaderCmd help. - "getblockheader--synopsis": "Returns information about a block header given its hash.", - "getblockheader-hash": "The hash of the block", - "getblockheader-verbose": "Specifies the block header is returned as a JSON object instead of hex-encoded string", - "getblockheader--condition0": "verbose=false", - "getblockheader--condition1": "verbose=true", - "getblockheader--result0": "The block header hash", - - // GetBlockHeaderVerboseResult help. - "getblockheaderverboseresult-hash": "The hash of the block (same as provided)", - "getblockheaderverboseresult-confirmations": "The number of confirmations", - "getblockheaderverboseresult-height": "The height of the block in the block chain", - "getblockheaderverboseresult-version": "The block version", - "getblockheaderverboseresult-merkleroot": "Root hash of the merkle tree", - "getblockheaderverboseresult-time": "The block time in seconds since 1 Jan 1970 GMT", - "getblockheaderverboseresult-nonce": "The block nonce", - "getblockheaderverboseresult-bits": "The bits which represent the block difficulty", - "getblockheaderverboseresult-difficulty": "The proof-of-work difficulty as a multiple of the minimum difficulty", - "getblockheaderverboseresult-previousblockhash": "The hash of the previous block", - "getblockheaderverboseresult-nextblockhash": "The hash of the next block (only if there is one)", - // TemplateRequest help. "templaterequest-mode": "This is 'template', 'proposal', or omitted", "templaterequest-capabilities": "List of capabilities", @@ -396,13 +375,6 @@ var helpDescsEnUS = map[string]string{ // GetInfoCmd help. "getinfo--synopsis": "Returns a JSON object containing various state info.", - // GetMempoolInfoCmd help. - "getmempoolinfo--synopsis": "Returns memory pool information", - - // GetMempoolInfoResult help. - "getmempoolinforesult-bytes": "Size in bytes of the mempool", - "getmempoolinforesult-size": "Number of transactions in the mempool", - // GetMiningInfoResult help. "getmininginforesult-blocks": "Height of the latest best block", "getmininginforesult-currentblocksize": "Size of the latest best block", @@ -711,7 +683,6 @@ var rpcResultTypes = map[string][]interface{}{ "getblock": []interface{}{(*string)(nil), (*dcrjson.GetBlockVerboseResult)(nil)}, "getblockcount": []interface{}{(*int64)(nil)}, "getblockhash": []interface{}{(*string)(nil)}, - "getblockheader": []interface{}{(*string)(nil), (*dcrjson.GetBlockHeaderVerboseResult)(nil)}, "getblocktemplate": []interface{}{(*dcrjson.GetBlockTemplateResult)(nil), (*string)(nil), nil}, "getconnectioncount": []interface{}{(*int32)(nil)}, "getcurrentnet": []interface{}{(*uint32)(nil)}, @@ -720,7 +691,6 @@ var rpcResultTypes = map[string][]interface{}{ "getgenerate": []interface{}{(*bool)(nil)}, "gethashespersec": []interface{}{(*float64)(nil)}, "getinfo": []interface{}{(*dcrjson.InfoChainResult)(nil)}, - "getmempoolinfo": []interface{}{(*dcrjson.GetMempoolInfoResult)(nil)}, "getmininginfo": []interface{}{(*dcrjson.GetMiningInfoResult)(nil)}, "getnettotals": []interface{}{(*dcrjson.GetNetTotalsResult)(nil)}, "getnetworkhashps": []interface{}{(*int64)(nil)}, diff --git a/rpcwebsocket.go b/rpcwebsocket.go index 0c5050e0..00b4d075 100644 --- a/rpcwebsocket.go +++ b/rpcwebsocket.go @@ -323,7 +323,7 @@ func (m *wsNotificationManager) NotifyMempoolTx(tx *dcrutil.Tx, isNew bool) { // the tickets eligible to vote on it). type WinningTicketsNtfnData struct { BlockHash chainhash.Hash - BlockHeight int32 + BlockHeight int64 Tickets []chainhash.Hash } @@ -331,7 +331,7 @@ type WinningTicketsNtfnData struct { // stake difficulty notifications. type StakeDifficultyNtfnData struct { BlockHash chainhash.Hash - BlockHeight int32 + BlockHeight int64 StakeDifficulty int64 } @@ -868,8 +868,8 @@ func (m *wsNotificationManager) notifyForNewTx(clients map[chan struct{}]*wsClie } net := m.server.server.chainParams - rawTx, err := createTxRawResult(net, mtx, txShaStr, nil, - "", 0, wire.NullBlockIndex, 0) + rawTx, err := createTxRawResult(net, txShaStr, mtx, nil, + 0, nil, int64(wire.NullBlockHeight), wire.NullBlockIndex) if err != nil { return } @@ -2040,8 +2040,8 @@ type rescanKeys struct { fallbacks map[string]struct{} pubKeyHashes map[[ripemd160.Size]byte]struct{} scriptHashes map[[ripemd160.Size]byte]struct{} - compressedPubKeys map[[33]byte]struct{} - uncompressedPubKeys map[[65]byte]struct{} + compressedPubkeys map[[33]byte]struct{} + uncompressedPubkeys map[[65]byte]struct{} unspent map[wire.OutPoint]struct{} } @@ -2165,14 +2165,14 @@ func rescanBlock(wsc *wsClient, lookups *rescanKeys, blk *dcrutil.Block, case 33: // Compressed var key [33]byte copy(key[:], sa) - if _, ok := lookups.compressedPubKeys[key]; ok { + if _, ok := lookups.compressedPubkeys[key]; ok { found = true } case 65: // Uncompressed var key [65]byte copy(key[:], sa) - if _, ok := lookups.uncompressedPubKeys[key]; ok { + if _, ok := lookups.uncompressedPubkeys[key]; ok { found = true } @@ -2259,7 +2259,7 @@ func rescanBlock(wsc *wsClient, lookups *rescanKeys, blk *dcrutil.Block, // verifies that the new range of blocks is on the same fork as a previous // range of blocks. If this condition does not hold true, the JSON-RPC error // for an unrecoverable reorganize is returned. -func recoverFromReorg(db database.Db, minBlock, maxBlock int32, +func recoverFromReorg(db database.Db, minBlock, maxBlock int64, lastBlock *dcrutil.Block) ([]chainhash.Hash, error) { hashList, err := db.FetchHeightRange(minBlock, maxBlock) @@ -2392,14 +2392,14 @@ func scanMempool(wsc *wsClient, lookups *rescanKeys) { case 33: // Compressed var key [33]byte copy(key[:], sa) - if _, ok := lookups.compressedPubKeys[key]; ok { + if _, ok := lookups.compressedPubkeys[key]; ok { found = true } case 65: // Uncompressed var key [65]byte copy(key[:], sa) - if _, ok := lookups.uncompressedPubKeys[key]; ok { + if _, ok := lookups.uncompressedPubkeys[key]; ok { found = true } @@ -2516,8 +2516,8 @@ func handleRescan(wsc *wsClient, icmd interface{}) (interface{}, error) { fallbacks: map[string]struct{}{}, pubKeyHashes: map[[ripemd160.Size]byte]struct{}{}, scriptHashes: map[[ripemd160.Size]byte]struct{}{}, - compressedPubKeys: map[[33]byte]struct{}{}, - uncompressedPubKeys: map[[65]byte]struct{}{}, + compressedPubkeys: map[[33]byte]struct{}{}, + uncompressedPubkeys: map[[65]byte]struct{}{}, unspent: map[wire.OutPoint]struct{}{}, } var compressedPubkey [33]byte @@ -2544,11 +2544,11 @@ func handleRescan(wsc *wsClient, icmd interface{}) (interface{}, error) { switch len(pubkeyBytes) { case 33: // Compressed copy(compressedPubkey[:], pubkeyBytes) - lookups.compressedPubKeys[compressedPubkey] = struct{}{} + lookups.compressedPubkeys[compressedPubkey] = struct{}{} case 65: // Uncompressed copy(uncompressedPubkey[:], pubkeyBytes) - lookups.uncompressedPubKeys[uncompressedPubkey] = struct{}{} + lookups.uncompressedPubkeys[uncompressedPubkey] = struct{}{} default: jsonErr := dcrjson.RPCError{ @@ -2697,7 +2697,7 @@ fetchRange: // A goto is used to branch executation back to // before the range was evaluated, as it must be // reevaluated for the new hashList. - minBlock += int32(i) + minBlock += int64(i) hashList, err = recoverFromReorg(db, minBlock, maxBlock, lastBlock) if err != nil { @@ -2744,7 +2744,7 @@ fetchRange: return nil, &ErrRescanReorg } - minBlock += int32(i) + minBlock += int64(i) hashList, err = recoverFromReorg(db, minBlock, maxBlock, lastBlock) if err != nil { @@ -2799,7 +2799,7 @@ fetchRange: } } - minBlock += int32(len(hashList)) + minBlock += int64(len(hashList)) } // Scan the mempool for addresses. diff --git a/sample-dcrd.conf b/sample-dcrd.conf index 9d383686..f06576dd 100644 --- a/sample-dcrd.conf +++ b/sample-dcrd.conf @@ -198,33 +198,6 @@ ; server without having to remove credentials from the config file. ; norpc=1 -; Use the following setting to disable TLS for the RPC server. NOTE: This -; option only works if the RPC server is bound to localhost interfaces (which is -; the default). -; notls=1 - -; ------------------------------------------------------------------------------ -; Mempool Settings - The following options -; ------------------------------------------------------------------------------ - -; Rate-limit free transactions to the value 15 * 1000 bytes per -; minute. -; limitfreerelay=15 - -; Require high priority for relaying free or low-fee transactions. -; norelaypriority=0 - -; Limit orphan transaction pool to 1000 transactions. -; maxorphantx=1000 - -; ------------------------------------------------------------------------------ -; Optional Transaction Indexes -; ------------------------------------------------------------------------------ - -; Build and maintain a full address-based transaction index. -; addrindex=1 -; Delete the entire address index on start up, then exit. -; dropaddrindex=0 ; ------------------------------------------------------------------------------ ; Coin Generation (Mining) Settings - The following options control the diff --git a/server.go b/server.go index 5afee8ef..0b9e1243 100644 --- a/server.go +++ b/server.go @@ -43,6 +43,10 @@ const ( // server. supportedServices = wire.SFNodeNetwork + // connectionRetryInterval is the amount of time to wait in between + // retries when connecting to persistent peers. + connectionRetryInterval = time.Second * 10 + // defaultMaxOutbound is the default number of max outbound peers. defaultMaxOutbound = 8 ) @@ -308,9 +312,7 @@ func (s *server) handleDonePeerMsg(state *peerState, p *peer) { // Issue an asynchronous reconnect if the peer was a // persistent outbound connection. if !p.inbound && p.persistent && atomic.LoadInt32(&s.shutdown) == 0 { - delete(list, e) e = newOutboundPeer(s, p.addr, true, p.retryCount+1) - list[e] = struct{}{} return } if !p.inbound { diff --git a/txscript/error.go b/txscript/error.go index f5567108..4314f096 100644 --- a/txscript/error.go +++ b/txscript/error.go @@ -30,11 +30,11 @@ var ( // ErrStackOpDisabled is returned when a disabled opcode is encountered // in the script. - ErrStackOpDisabled = errors.New("disabled opcode") + ErrStackOpDisabled = errors.New("Disabled Opcode") // ErrStackVerifyFailed is returned when one of the OP_VERIFY or // OP_*VERIFY instructions is executed and the conditions fails. - ErrStackVerifyFailed = errors.New("verify failed") + ErrStackVerifyFailed = errors.New("Verify failed") // ErrStackNumberTooBig is returned when the argument for an opcode that // should be an offset is obviously far too large. @@ -42,15 +42,15 @@ var ( // ErrStackInvalidOpcode is returned when an opcode marked as invalid or // a completely undefined opcode is encountered. - ErrStackInvalidOpcode = errors.New("invalid opcode") + ErrStackInvalidOpcode = errors.New("Invalid Opcode") // ErrStackReservedOpcode is returned when an opcode marked as reserved // is encountered. - ErrStackReservedOpcode = errors.New("reserved opcode") + ErrStackReservedOpcode = errors.New("Reserved Opcode") // ErrStackEarlyReturn is returned when OP_RETURN is executed in the // script. - ErrStackEarlyReturn = errors.New("script returned early") + ErrStackEarlyReturn = errors.New("Script returned early") // ErrStackNoIf is returned if an OP_ELSE or OP_ENDIF is encountered // without first having an OP_IF or OP_NOTIF in the script. @@ -60,17 +60,17 @@ var ( // without and OP_ENDIF to correspond to a conditional expression. ErrStackMissingEndif = fmt.Errorf("execute fail, in conditional execution") - // ErrStackTooManyPubKeys is returned if an OP_CHECKMULTISIG is + // ErrStackTooManyPubkeys is returned if an OP_CHECKMULTISIG is // encountered with more than MaxPubKeysPerMultiSig pubkeys present. - ErrStackTooManyPubKeys = errors.New("invalid pubkey count in OP_CHECKMULTISIG") + ErrStackTooManyPubkeys = errors.New("Invalid pubkey count in OP_CHECKMULTISIG") // ErrStackTooManyOperations is returned if a script has more than // MaxOpsPerScript opcodes that do not push data. - ErrStackTooManyOperations = errors.New("too many operations in script") + ErrStackTooManyOperations = errors.New("Too many operations in script") // ErrStackElementTooBig is returned if the size of an element to be // pushed to the stack is over MaxScriptElementSize. - ErrStackElementTooBig = errors.New("element in script too large") + ErrStackElementTooBig = errors.New("Element in script too large") // ErrStackUnknownAddress is returned when ScriptToAddrHash does not // recognise the pattern of the script and thus can not find the address @@ -84,12 +84,12 @@ var ( // ErrStackScriptUnfinished is returned when CheckErrorCondition is // called on a script that has not finished executing. - ErrStackScriptUnfinished = errors.New("error check when script unfinished") + ErrStackScriptUnfinished = errors.New("Error check when script unfinished") // ErrStackEmptyStack is returned when the stack is empty at the end of // execution. Normal operation requires that a boolean is on top of the // stack when the scripts have finished executing. - ErrStackEmptyStack = errors.New("stack empty at end of execution") + ErrStackEmptyStack = errors.New("Stack empty at end of execution") // ErrStackP2SHNonPushOnly is returned when a Pay-to-Script-Hash // transaction is encountered and the ScriptSig does operations other @@ -107,7 +107,7 @@ var ( // ErrStackInvalidIndex is returned when an out-of-bounds index was // passed to a function. - ErrStackInvalidIndex = errors.New("invalid script index") + ErrStackInvalidIndex = errors.New("Invalid script index") // ErrStackNonPushOnly is returned when ScriptInfo is called with a // pkScript that peforms operations other that pushing data to the stack. @@ -115,7 +115,7 @@ var ( // ErrStackOverflow is returned when stack and altstack combined depth // is over the limit. - ErrStackOverflow = errors.New("stack overflow") + ErrStackOverflow = errors.New("Stacks overflowed") // ErrStackInvalidLowSSignature is returned when the ScriptVerifyLowS // flag is set and the script contains any signatures whose S values diff --git a/txscript/opcode.go b/txscript/opcode.go index fbc22da9..aaab8463 100644 --- a/txscript/opcode.go +++ b/txscript/opcode.go @@ -2455,7 +2455,7 @@ func opcodeCheckMultiSig(op *parsedOpcode, vm *Engine) error { numPubKeys := int(numKeys.Int32()) if numPubKeys < 0 || numPubKeys > MaxPubKeysPerMultiSig { - return ErrStackTooManyPubKeys + return ErrStackTooManyPubkeys } vm.numOps += numPubKeys if vm.numOps > MaxOpsPerScript { diff --git a/txscript/script.go b/txscript/script.go index c523e231..70cbd0a7 100644 --- a/txscript/script.go +++ b/txscript/script.go @@ -328,6 +328,9 @@ func calcSignatureHash(script []parsedOpcode, hashType SigHashType, // inputs that are not currently being processed. txCopy := tx.Copy() for i := range txCopy.TxIn { + var txIn wire.TxIn + txIn = *txCopy.TxIn[i] + txCopy.TxIn[i] = &txIn if i == idx { // UnparseScript cannot fail here because removeOpcode // above only returns a valid script. @@ -338,6 +341,13 @@ func calcSignatureHash(script []parsedOpcode, hashType SigHashType, } } + // Default behavior has all outputs set up. + for i := range txCopy.TxOut { + var txOut wire.TxOut + txOut = *txCopy.TxOut[i] + txCopy.TxOut[i] = &txOut + } + switch hashType & sigHashMask { case SigHashNone: txCopy.TxOut = txCopy.TxOut[0:0] // Empty slice. @@ -381,9 +391,9 @@ func calcSignatureHash(script []parsedOpcode, hashType SigHashType, } // The final hash (message to sign) is the hash of: - // 1) the hash type (encoded as a 4-byte little-endian value) || - // 2) hash of the prefix || - // 3) hash of the witness for signing + // 1) hash of the prefix || + // 2) hash of the witness for signing || + // 3) the hash type (encoded as a 4-byte little-endian value) var wbuf bytes.Buffer binary.Write(&wbuf, binary.LittleEndian, uint32(hashType)) @@ -520,15 +530,3 @@ func GetPreciseSigOpCount(scriptSig, scriptPubKey []byte, bip16 bool) int { shPops, _ := parseScript(shScript) return getSigOpCount(shPops, true) } - -// IsUnspendable returns whether the passed public key script is unspendable, or -// guaranteed to fail at execution. This allows inputs to be pruned instantly -// when entering the UTXO set. -func IsUnspendable(pkScript []byte) bool { - pops, err := parseScript(pkScript) - if err != nil { - return true - } - - return len(pops) > 0 && pops[0].opcode.value == OP_RETURN -} diff --git a/txscript/script_test.go b/txscript/script_test.go index 9db572f4..d706d153 100644 --- a/txscript/script_test.go +++ b/txscript/script_test.go @@ -576,38 +576,3 @@ func TestCalcSignatureHash(t *testing.T) { msg3) } } - -// TestIsUnspendable ensures the IsUnspendable function returns the expected -// results. -func TestIsUnspendable(t *testing.T) { - t.Parallel() - - tests := []struct { - name string - pkScript []byte - expected bool - }{ - { - // Unspendable - pkScript: []byte{0x6a, 0x04, 0x74, 0x65, 0x73, 0x74}, - expected: true, - }, - { - // Spendable - pkScript: []byte{0x76, 0xa9, 0x14, 0x29, 0x95, 0xa0, - 0xfe, 0x68, 0x43, 0xfa, 0x9b, 0x95, 0x45, - 0x97, 0xf0, 0xdc, 0xa7, 0xa4, 0x4d, 0xf6, - 0xfa, 0x0b, 0x5c, 0x88, 0xac}, - expected: false, - }, - } - - for i, test := range tests { - res := txscript.IsUnspendable(test.pkScript) - if res != test.expected { - t.Errorf("TestIsUnspendable #%d failed: got %v want %v", - i, res, test.expected) - continue - } - } -} diff --git a/txscript/standard.go b/txscript/standard.go index 81d2ef91..1d5ec00f 100644 --- a/txscript/standard.go +++ b/txscript/standard.go @@ -249,7 +249,7 @@ func IsMultisigSigScript(script []byte) bool { func isNullData(pops []parsedOpcode) bool { // A nulldata transaction is either a single OP_RETURN or an // OP_RETURN SMALLDATA (where SMALLDATA is a data push up to - // MaxDataCarrierSize bytes). + // maxDataCarrierSize bytes). l := len(pops) if l == 1 && pops[0].opcode.value == OP_RETURN { return true diff --git a/wire/blockheader.go b/wire/blockheader.go index 2eefa5dc..4e8577f0 100644 --- a/wire/blockheader.go +++ b/wire/blockheader.go @@ -95,22 +95,6 @@ func (h *BlockHeader) BlockSha() chainhash.Hash { return chainhash.HashFuncH(buf.Bytes()) } -// BtcDecode decodes r using the bitcoin protocol encoding into the receiver. -// This is part of the Message interface implementation. -// See Deserialize for decoding block headers stored to disk, such as in a -// database, as opposed to decoding block headers from the wire. -func (h *BlockHeader) BtcDecode(r io.Reader, pver uint32) error { - return readBlockHeader(r, pver, h) -} - -// BtcEncode encodes the receiver to w using the bitcoin protocol encoding. -// This is part of the Message interface implementation. -// See Serialize for encoding block headers to be stored to disk, such as in a -// database, as opposed to encoding block headers for the wire. -func (h *BlockHeader) BtcEncode(w io.Writer, pver uint32) error { - return writeBlockHeader(w, pver, h) -} - // Deserialize decodes a block header from r into the receiver using a format // that is suitable for long-term storage such as a database while respecting // the Version field. diff --git a/wire/blockheader_test.go b/wire/blockheader_test.go index 601532fc..7476c9b0 100644 --- a/wire/blockheader_test.go +++ b/wire/blockheader_test.go @@ -113,7 +113,6 @@ func TestBlockHeader(t *testing.T) { // protocol versions. func TestBlockHeaderWire(t *testing.T) { nonce := uint32(123123) // 0x1e0f3 - pver := uint32(70001) /*bh := dcrwire.NewBlockHeader( &hash, @@ -217,15 +216,14 @@ func TestBlockHeaderWire(t *testing.T) { continue } - buf.Reset() - err = test.in.BtcEncode(&buf, pver) + b, err := wire.TstBytesBlockHeader(test.in) if err != nil { - t.Errorf("BtcEncode #%d error %v", i, err) + t.Errorf("writeBlockHeader #%d error %v", i, err) continue } - if !bytes.Equal(buf.Bytes(), test.buf) { - t.Errorf("BtcEncode #%d\n got: %s want: %s", i, - spew.Sdump(buf.Bytes()), spew.Sdump(test.buf)) + if !bytes.Equal(b, test.buf) { + t.Errorf("writeBlockHeader #%d\n got: %s want: %s", i, + spew.Sdump(b), spew.Sdump(test.buf)) continue } @@ -242,18 +240,6 @@ func TestBlockHeaderWire(t *testing.T) { spew.Sdump(&bh), spew.Sdump(test.out)) continue } - - rbuf = bytes.NewReader(test.buf) - err = bh.BtcDecode(rbuf, pver) - if err != nil { - t.Errorf("BtcDecode #%d error %v", i, err) - continue - } - if !reflect.DeepEqual(&bh, test.out) { - t.Errorf("BtcDecode #%d\n got: %s want: %s", i, - spew.Sdump(&bh), spew.Sdump(test.out)) - continue - } } }