Skip to content

Some refactoring and add the "generateblock" RPC method#39

Merged
galpHub merged 6 commits intoDiviProject:Developmentfrom
domob1812:generateblock-rpc
Oct 5, 2020
Merged

Some refactoring and add the "generateblock" RPC method#39
galpHub merged 6 commits intoDiviProject:Developmentfrom
domob1812:generateblock-rpc

Conversation

@domob1812
Copy link
Copy Markdown

This contains some of the harmless (not changing behaviour / introducing a fork) commits from #38, split out for easier review and merging. In particular, some small cleanups / refactorings / fixes as well as the new generateblock RPC method. That method can be used to generate a single block on regtest (like setgenerate True 1), and allows extra control that can be useful for testing. (In particular, a list of custom transactions can be added apart from the normal mempool logic, and a custom coinstake transaction can be used instead of generating one.)

Mark the new StakingVaultFunding.py regtest as executable, so that
it can be run directly from a command-line (without having to type
"python" in front, like the other tests).  It already has a shebang
line anyway.
Remove some of the members in BlockFactory, which are actually only
needed in the constructor and passed on to the constructors of other
members (but not directly in BlockFactory).  This makes the code more
explicit about what is actually needed / used where.
When trying to sign a transaction with a keystore and the input
is a vault script, try signing it both as owner and as staker (if
signing as owner fails).

This will allow signing the stake transaction correctly, and also
will be useful for testing the OP_REQUIRE_COINSTAKE fork.
CScript's operator<< for pushing data is not necessarily doing it in
the minimal way (namely when a single-byte op-code like OP_5 or
OP_1NEGATE can be used).  This means that CombineSignature (e.g. from
using signrawtransaction) may produce signatures that fail verification
with SCRIPT_VERIFY_MINIMALDATA.  For "normal" signature types like
P2PKH this does not happen; but the OP_0 and OP_1 in the signature
of vault scripts trigger the bug.

This fixes CombineSignatures to push data in a minimal way.  It also
adds a unit test that SignSignatures + CombineSignatures works for
signing vault scripts both as vault and owner.
The new generateblock RPC method can be used to mine a block on demand
(on regtest), while also providing extra control for testing.  In
particular, custom transactions can be included into the block without
verifying them through normal means.  In the future, more such things
might be added as needed for testing, e.g. a custom coinstake tx.
Allow passing a custom coinstake transaction to generateblock, which
will then be used instead of a created one.  It is the caller's
responsibility to make sure this yields a valid block; but on regtest
with minimal dificulty, that is not hard if enough coinage is spent.
@galpHub galpHub merged commit d501f3d into DiviProject:Development Oct 5, 2020
@domob1812 domob1812 deleted the generateblock-rpc branch October 5, 2020 14:03
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