Skip to content

Dynamic federations#642

Merged
stevenroose merged 62 commits intoElementsProject:masterfrom
instagibbs:dyna_fed_squashed
Sep 6, 2019
Merged

Dynamic federations#642
stevenroose merged 62 commits intoElementsProject:masterfrom
instagibbs:dyna_fed_squashed

Conversation

@instagibbs
Copy link
Contributor

@instagibbs instagibbs commented May 31, 2019

This is a proposal implementation of something myself and Andrew have been working on, to enable dynamic membership in the blocksigning set, fedpeg signing set, and under the same coordination mechanism, the PAK enforcement.

At a really high level:

  1. If 4/5 of last N(what we call an epoch length) blocks signal desire for a change in the parameters of the system, they are replaced with the proposed. These changes can be proposed/driven by getnewblockhex.
  2. Once dynamic federations is active(versionbits deployment), signblockscripts can only be native segwit scripts, in other words, must be a version byte followed by the witness program. The blockheader now has a witness stack as well.
  3. The fedpegscript of last N epochs are both allowed as a grace period for users putting money into the system.
  4. PAK enforcement has been upgraded to consensus-enforcement once dynamic federations activates

A design document is forthcoming.

@instagibbs instagibbs requested a review from stevenroose May 31, 2019 21:06
@instagibbs
Copy link
Contributor Author

Proposed changes:

  1. Tighten up extension_space for pak-enforcing nodes so that proposals must only have proper key entries
  2. Forbid P2SH proposals for signblockscript
  3. Forbid OP_DEPTH for proposals for fedpegscript (we want to forbid our hacky liquidv1 script which tweaks some keys but not all, and OP_DEPTH is not in miniscript)

@instagibbs instagibbs changed the title Dynamic federations [WIP] Dynamic federations Jun 6, 2019
@instagibbs instagibbs force-pushed the dyna_fed_squashed branch from 7c0b5ff to 7c7c4cd Compare June 6, 2019 09:49
@instagibbs
Copy link
Contributor Author

rebased on master

@apoelstra
Copy link
Member

14:33:26 bash@tate-module ~$ elements-cli -chain=elementsregtest getblockheader 13f6c6e9c224792f09fc9021cf9228f4fb3e97a26e6a4ba4e500ea8fc1928459
{
  "hash": "13f6c6e9c224792f09fc9021cf9228f4fb3e97a26e6a4ba4e500ea8fc1928459",
  "confirmations": 1,
  "height": 1,
  "version": 536870912,
  "versionHex": "20000000",
  "merkleroot": "43732c47c526dfdb57203e66c2ebf9c0bff23189737b6ef432bd5040b5a697a2",
  "time": 1559831118,
  "mediantime": 1559831118,
  "signblock_witness_asm": "",
  "signblock_witness_hex": "",
  "dynamic_parameters": {
    "current": {
      "signblockscript": "00204ae81572f06e1b88fd5ced7a1a000945432e83e1551e6f721ee9c00b8cc33260",
      "max_block_witness": 75,
      "fedpegscript": "",
      "extension_space": [
      ]
    },
    "proposed": {
      "signblockscript": "",
      "max_block_witness": 0,
      "fedpegscript": "",
      "extension_space": [
      ]
    }
  },
  "nTx": 1,
  "previousblockhash": "cd179c84c35f51825f20a3b91a18d45f0c53b5ceb744a5b6ef8f0babe809396f"
}

seems that fedpegscript and extension_space are empty even though getsidechaininfo and getblockchaininfo respectively show that it should be populated. Also we should rename extension_space.

@apoelstra
Copy link
Member

After some in-person discussion:

  1. The above output is expected because this is not a transition block, so the CPE is empty (except it has the signblockscript so that contextless validators can check the witness).
  2. For both fedpeg and signblock, we want to encode both the witness program and witness script in the CPE. For non-v0 programs the "witness program" is unconstrained, to be compatible with Taproot where there will be no such program.

@instagibbs
Copy link
Contributor Author

TODO:

to support taproot upgrade with fedpegscripts, we should always include the serialized scriptPubKey of the fedpegscript, which includes the version byte(right now we're implicitly understanding it as v0 segwit script). We should also include a followup vector of bytes that has no consensus meaning for now but could later be used to include taproot-related data.

Support signaling the peg-in confirmation depth during transitions, to be able to smoothly increase or decrease this value as necessary as a network matures

@instagibbs
Copy link
Contributor Author

instagibbs commented Jun 7, 2019

fedpegscripts must match the v0 scriptPubKey's hash, if v1+, then no consensus meaning whatsoever, and all otherwise valid peg-ins are valid

@ElementsProject ElementsProject deleted a comment from stevenroose Jun 7, 2019
@stevenroose
Copy link
Contributor

Did a first pass of review over everything. So utACK 7c7c4cd.

@instagibbs
Copy link
Contributor Author

simple-ish rebase on master

@instagibbs
Copy link
Contributor Author

@stevenroose addressed all comments, taking all renaming suggestions as commits on top

@instagibbs instagibbs force-pushed the dyna_fed_squashed branch 4 times, most recently from 6b93f0e to e002aef Compare June 19, 2019 15:03
@instagibbs
Copy link
Contributor Author

All feedback/improvements have been included.

I'm getting an intermittant error for feature_pak.py however:

2019-06-19T15:43:16.821000Z TestFramework (INFO): Initializing test directory /tmp/bitcoin_func_test_3ce4qu9m
2019-06-19T15:43:17.492000Z TestFramework (INFO): Test wallet PAK
2019-06-19T15:43:18.610000Z TestFramework (INFO): Test mempool enforcement of PAK peg-outs
2019-06-19T15:43:26.648000Z TestFramework (ERROR): JSONRPC error
Traceback (most recent call last):
  File "/home/instagibbs/elements-dev/elements/test/functional/test_framework/test_framework.py", line 177, in main
    self.run_test()
  File "./test/functional/feature_pak.py", line 127, in run_test
    block = self.nodes[1].getnewblockhex(0, {"signblockscript":WSH_OP_TRUE, "max_block_witness":3, "fedpegscript":"51", "extension_space":extension_space_proposal})
  File "/home/instagibbs/elements-dev/elements/test/functional/test_framework/coverage.py", line 47, in __call__
    return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs)
  File "/home/instagibbs/elements-dev/elements/test/functional/test_framework/authproxy.py", line 136, in __call__
    raise JSONRPCException(response['error'])
test_framework.authproxy.JSONRPCException: CreateNewBlock: TestBlockValidity failed: bad-pak-tx (code 16) (-1)
2019-06-19T15:43:26.700000Z TestFramework (INFO): Stopping nodes
2019-06-19T15:43:27.055000Z TestFramework (WARNING): Not cleaning up dir /tmp/bitcoin_func_test_3ce4qu9m
2019-06-19T15:43:27.055000Z TestFramework (ERROR): Test failed. Test logging available at /tmp/bitcoin_func_test_3ce4qu9m/test_framework.log
2019-06-19T15:43:27.056000Z TestFramework (ERROR): Hint: Call /home/instagibbs/elements-dev/elements/test/functional/combine_logs.py '/tmp/bitcoin_func_test_3ce4qu9m' to consolidate all logs

I will try to determine if this is a real issue.

@instagibbs instagibbs changed the title [WIP] Dynamic federations Dynamic federations Jun 19, 2019
@instagibbs
Copy link
Contributor Author

ready for review

@instagibbs
Copy link
Contributor Author

Test failure was a case we weren't accounting for, general re-orgs. Put a heavy-handed solution there since we don't expect re-orgs, for minimal code changes.

@instagibbs
Copy link
Contributor Author

getpeginaddress should return warnings when transitions are signaled

@instagibbs
Copy link
Contributor Author

Added a fedpeg test run that tests when dynafed is active but the original fedpegscript is still in play, and dynafed active, with newest fedpeg only in play. This catches the issue @apoelstra pointed out with getpeginaddress and catches some errors I previously encountered manually with RPC calls using the original list and succeeding.

@instagibbs
Copy link
Contributor Author

I relaxed the number of epochs a peg-in is valid for to M, where M is set per-chain.

@stevenroose
Copy link
Contributor

ACK f7905d6

stevenroose added a commit that referenced this pull request Sep 6, 2019
f7905d6 Generalize the number of epochs old a peg-in can be and still be valid (Gregory Sanders)
b105ff4 feature_fedpeg.py: Run in various dynafed transition settings (Gregory Sanders)
feef196 Fix compilation of raw transaction operations with peg-in inputs (Gregory Sanders)
953dd82 p2sh-wrap peg-in addresses if fedpeg_program is p2sh-wrapped (Gregory Sanders)
e2be235 Refactor IsPAKValid to not magically acquire chainparams (Gregory Sanders)
ecdefc5 Remove script/standard dependence of ContextualCheckDynaFedHeader (Gregory Sanders)
59bed57 Remove dyanfed.cpp's dependency on script/standard.h (Gregory Sanders)
50a2b59 After a reorg, boot all peg-ins and peg-outs from mempool (Gregory Sanders)
6000752 Enforce PAK checks on dynafed proposals (Gregory Sanders)
dce4cec Replace fedpeg template init check for pak one (Gregory Sanders)
afdf023 Update python test framework for DynaFedParamEntry fedpeg program (Gregory Sanders)
95d8339 Add functional test for illegal proposals (Gregory Sanders)
1baad6b Update dynafed functional test to new behavior (Gregory Sanders)
a3cf151 fixup proposal checks (Gregory Sanders)
04cc767 getnewblockhex fills out proposal fedpeg program (Gregory Sanders)
44f55d3 Make future parent segwit versions in fedpegscripts be vacuously true (Gregory Sanders)
d7faffd Add dynafed proposal restrictions (Gregory Sanders)
37f90ba Add description of NextBlockIsParameterTransition (Gregory Sanders)
d9387cb Remove misleading comment for ContextualCheckDynaFedHeader use (Gregory Sanders)
bd11097 Add fedpeg_program field in dynafed header (Gregory Sanders)
4ad2b80 CreatePAKListFromExtensionSpace just uses FromBytes for correctness (Gregory Sanders)
6a5eaa1 Remove short-circuit dynafed vote fail for readability (Gregory Sanders)
dddc040 s/m_dyna_params/m_dynafed_params/ (Gregory Sanders)
6ed63c1 Light explanation of dynamic federations fields (Gregory Sanders)
1599638 s/ConsensusParamEntry/DynaFedParamEntry/ (Gregory Sanders)
642260a s/m_sbs_wit_limit/m_signblock_witness_limit/ (Gregory Sanders)
b668046 s/HF_MASK/DYNAFED_HF_MASK/ (Gregory Sanders)
0fd39ed s/d_params/dynafed_params/ (Gregory Sanders)
1779956 signrawtransaction* should use up to date fedpegscript for peg-in signing (Gregory Sanders)
47db75e Dynafed RPC support, tests, and deployment for custom chains (Gregory Sanders)
aac354b OP_TRUE outputs should be allowed to be segwit-ified by decodescript (Gregory Sanders)
055514b Have removeForBlock boot transactions when required (Gregory Sanders)
525b24c Expose fedpeg fetching to consensus and mempool internals (Gregory Sanders)
4ac437b GetTransactionSigOpCost shouldn't need fedpegscript to evaluate (Gregory Sanders)
5097c38 Add and update startup args for dynafed (Gregory Sanders)
24535d6 Add unused dynamic genesis block style in chainparams (Gregory Sanders)
d10c42a Create epoch length chainparam (Gregory Sanders)
b996a42 Set default of multi_data_permitted to enforce_pak (Gregory Sanders)
f6f6308 Correct comment about liquidv1 fedpeg matching template (Gregory Sanders)
4c00eb4 Miner should stop trying to account for old PAK system (Gregory Sanders)
0e10287 Add miner ability to make dynafed blocks (Gregory Sanders)
5d281e7 ContextualCheckBlockHeader: dynafed doesn't call CheckChallenge (Gregory Sanders)
9fe43cd Introduce contextual block checks for dynafed (Gregory Sanders)
3605505 Enable pak enforcement at mempool/block level when appropriate (Gregory Sanders)
802a055 ScriptHasValidPAKProof takes fedpeg as arg (Gregory Sanders)
89174e9 Remove old mempool-booting logic (Gregory Sanders)
edb865c Remove standardness checks for PAK (Gregory Sanders)
804cd9f Update PAK internals, helper functions (Gregory Sanders)
16b87ba Disable PAK loading from configuration on init, disable pak test (Gregory Sanders)
918896d Add inactive versionbits dynafed deployment (Gregory Sanders)
0a8565b ReadBlockFromDisk: do genesis block check before block proof check (Gregory Sanders)
6f0d924 Bump last old block version for versonbits due to elements (Gregory Sanders)
563cd93 Add python implementation of dynafed block serialization (Gregory Sanders)
8d3091b Deserialize merkle proofs without witness, which matters for dynafed (Gregory Sanders)
830f917 Add fedpegscript-fetching helper (Gregory Sanders)
b56fe14 calculate_contract: remove most template checks and assert in preperation for dynafed (Gregory Sanders)
fd63cee Add note on peg-in sigops (Gregory Sanders)
f17d7de Add dynafed helper functions (Gregory Sanders)
4aa5f99 Refactor block_proof to support dynafed (Gregory Sanders)
4e52f2c Add dynamic federation blockheader fields to chaindb serialization (Gregory Sanders)
a74accf Add dynamic federations blockheader serialization with HF bit (Gregory Sanders)
2845e78 Define dynamic federations primitives (Gregory Sanders)

Pull request description:

  This is a proposal implementation of something myself and Andrew have been working on, to enable dynamic membership in the blocksigning set, fedpeg signing set, and under the same coordination mechanism, the PAK enforcement.

  At a really high level:

  1) If 4/5 of last N(what we call an epoch length) blocks signal desire for a change in the parameters of the system, they are replaced with the proposed. These changes can be proposed/driven by `getnewblockhex`.
  2) Once dynamic federations is active(versionbits deployment), signblockscripts can only be native segwit scripts, in other words, must be a version byte followed by the witness program. The blockheader now has a witness stack as well.
  3) The fedpegscript of last N epochs are both allowed as a grace period for users putting money into the system.
  4) PAK enforcement has been upgraded to consensus-enforcement once dynamic federations activates

  A design document is forthcoming.

Tree-SHA512: 26c6e05c85adb77345d8d481f20e8095bc2f9e5ad7b9a8824008a056637af7c6e87e522b038a6c6c108889d60b2fd1d6ecbd3e0afe2b696579000d18b0f1ecad
@stevenroose stevenroose merged commit f7905d6 into ElementsProject:master Sep 6, 2019
apoelstra added a commit to apoelstra/elements that referenced this pull request Nov 3, 2020
apoelstra added a commit to apoelstra/elements that referenced this pull request Nov 6, 2020
FIXME: we disable standardness checks for the non-PAK node in the PAK tests.
This is because of a bug in Elements which causes non-PAK nodes to reject
pegouts for standardness reasons. Need to fix it after the rebase.
apoelstra added a commit to apoelstra/elements that referenced this pull request Nov 9, 2020
FIXME: we disable standardness checks for the non-PAK node in the PAK tests.
This is because of a bug in Elements which causes non-PAK nodes to reject
pegouts for standardness reasons. Need to fix it after the rebase.
apoelstra added a commit to apoelstra/elements that referenced this pull request Nov 10, 2020
FIXME: we disable standardness checks for the non-PAK node in the PAK tests.
This is because of a bug in Elements which causes non-PAK nodes to reject
pegouts for standardness reasons. Need to fix it after the rebase.
gwillen pushed a commit that referenced this pull request Mar 16, 2021
FIXME: we disable standardness checks for the non-PAK node in the PAK tests.
This is because of a bug in Elements which causes non-PAK nodes to reject
pegouts for standardness reasons. Need to fix it after the rebase.
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.

4 participants

Comments