minerblock: commit block once mined.
This commit is contained in:
parent
9e48947d2f
commit
390f7d8ddb
@ -1355,10 +1355,8 @@ RPC.prototype.__submitwork = co(function* _submitwork(data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
block.nonce = header.nonce;
|
||||
block.ts = header.ts;
|
||||
block.mutable = false;
|
||||
block.txs[0].mutable = false;
|
||||
attempt.commit(header.nonce);
|
||||
|
||||
try {
|
||||
yield this.chain.add(block);
|
||||
|
||||
@ -62,9 +62,11 @@ function MinerBlock(options) {
|
||||
this.witness = options.witness;
|
||||
this.address = options.address;
|
||||
this.network = Network.get(options.network);
|
||||
this.destroyed = false;
|
||||
this.reward = btcutils.getReward(this.height, this.network.halvingInterval);
|
||||
|
||||
this.destroyed = false;
|
||||
this.committed = false;
|
||||
|
||||
this.sigops = 0;
|
||||
this.weight = 0;
|
||||
this.fees = 0;
|
||||
@ -289,7 +291,7 @@ MinerBlock.prototype.addTX = function addTX(tx) {
|
||||
this.fees += tx.getFee();
|
||||
|
||||
// Add the tx to our block
|
||||
this.block.addTX(tx.clone());
|
||||
this.block.txs.push(tx.clone());
|
||||
|
||||
// Update coinbase value
|
||||
this.updateCoinbase();
|
||||
@ -387,9 +389,7 @@ MinerBlock.prototype.mine = function mine() {
|
||||
this.iterate();
|
||||
}
|
||||
|
||||
this.block.nonce = nonce;
|
||||
this.block.mutable = false;
|
||||
this.coinbase.mutable = false;
|
||||
this.commit(nonce);
|
||||
|
||||
return this.block;
|
||||
};
|
||||
@ -419,9 +419,7 @@ MinerBlock.prototype.mineAsync = co(function* mineAsync() {
|
||||
this.iterate();
|
||||
}
|
||||
|
||||
this.block.nonce = nonce;
|
||||
this.block.mutable = false;
|
||||
this.coinbase.mutable = false;
|
||||
this.commit(nonce);
|
||||
|
||||
return this.block;
|
||||
});
|
||||
@ -457,6 +455,27 @@ MinerBlock.prototype.iterate = function iterate() {
|
||||
this.updateNonce();
|
||||
};
|
||||
|
||||
/**
|
||||
* Commit and finalize mined block.
|
||||
* @returns {Block}
|
||||
*/
|
||||
|
||||
MinerBlock.prototype.commit = function commit(nonce) {
|
||||
var i, tx;
|
||||
|
||||
assert(!this.committed, 'Block is already committed.');
|
||||
|
||||
this.committed = true;
|
||||
this.block.nonce = nonce;
|
||||
this.block.mutable = false;
|
||||
this.coinbase.mutable = false;
|
||||
|
||||
for (i = 0; i < this.block.txs.length; i++) {
|
||||
tx = this.block.txs[i];
|
||||
tx.setBlock(this.block, i);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Send a progress report (emits `status`).
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user