Skip to content

Handle new ANON v2 getblocktemplate with developement fee and superbl…#35

Merged
egyptianbman merged 2 commits intos-nomp:masterfrom
anonymousbitcoin:anon-v2
Feb 19, 2019
Merged

Handle new ANON v2 getblocktemplate with developement fee and superbl…#35
egyptianbman merged 2 commits intos-nomp:masterfrom
anonymousbitcoin:anon-v2

Conversation

@nlevo
Copy link
Copy Markdown
Contributor

@nlevo nlevo commented Feb 7, 2019

This PR handles ANON development fee, and superblocks which will be activated by a Spork pretty soon.

  • ANON getblocktemplate provides an array of objects (coinbase_required_outputs). It contains all the required coinbase outputs (masternode, developement fund, superblocks).
  • Each object has the following keys: amount, script (hex), type.
  • 'type' can be the following: 'masternode', 'development' or 'superblock'

@nlevo nlevo closed this Feb 7, 2019
@nlevo nlevo reopened this Feb 7, 2019
Copy link
Copy Markdown
Member

@egyptianbman egyptianbman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for providing this PR! I just have a few minor requests.

}
} else {

} else if(rpcData.coinbase_required_outputs && rpcData.coinbase_required_outputs.length){
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix the alignment in this block? (should be four spaces)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

// keep track of total the amount of all outputs (except superblock) in coinbase_required_outputs array
let required_outputs_total = 0;
// loop through coinbase_required_outputs and add them to our coinbase transaction
for(let i = 0; i < rpcData.coinbase_required_outputs.length; i++){
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified with:

rpcData.coinbase_required_outputs.map(output => {
    // do something with the output -- i.e. output.script or output.amount
})

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

// let's find out if it's a superblock
// we ignore superblock's output value becuase it's not part of the block reward
// during superblocks the total output value of coinbase exceeds regular block reward
if(rpcData.coinbase_required_outputs[i].type !== "superblock")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if statements should have a space after the if as well as curly braces (even if only one-line).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

for(let i = 0; i < rpcData.coinbase_required_outputs.length; i++){

let script = new Buffer(rpcData.coinbase_required_outputs[i].script, 'hex')
let amount = rpcData.coinbase_required_outputs[i].amount;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these are only used once, it's preferred to pass the value directly to txb.addOutput below to minimize memory consumption.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

)
}
// we want to calculate pool fee using miner reward only
blockReward.total = blockReward.total - required_outputs_total;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified to: blockReward.total -= required_outputs_total

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


// masternode reward
// what if there is no masternode winner?
if(masternodeAddrHash)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix the alignment of this block and add curly braces?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Copy Markdown
Member

@egyptianbman egyptianbman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@egyptianbman egyptianbman merged commit 5e7c303 into s-nomp:master Feb 19, 2019
egyptianbman pushed a commit to 1ds/node-stratum-pool that referenced this pull request Feb 20, 2019
Handle new ANON v2 getblocktemplate with developement fee and superblocks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants