diff --git a/contrib/federation/blocksign.sh b/contrib/federation/blocksign.sh new file mode 100755 index 0000000000..87a179c730 --- /dev/null +++ b/contrib/federation/blocksign.sh @@ -0,0 +1,96 @@ +#!/bin/bash + +BIN=$(dirname $0)/../../src/elements + +ADDR0=2dg8TR1BtYs1BJPLdjSpWnhDgadEDXxKRM7 +PK0=02febf482b566f37b7b8a624e3bcb708ff745daa37389bcc381ea207efaa84d85c +SK0=cPpQ1dgHCiaPKmpCeuRBECfwaa5cJCj39n6j8vLmZ8ZgLJ6NQ4ce + +ADDR1=2dmHcVLR9xCbCnkVGAAaJyps5Ak7hPkNEWu +PK1=039a70503f82b475f0388a0a187b4bef35f54d4e63e6ea235790f03ac070750b93 +SK1=cStpof1xJ6yvGhxMmxKrJPfV8D8V8VGgftJPffyZk8eaJmFWZMFR + +ADDR2=2dZwNCpB4xHqhexTavHdFXHjRRCLALpkYmm +PK2=022ceed2aa5b56abf6765135daf8970bd0be44e890d0b493eb6efb824be6c29197 +SK2=cVNMk5uTaAFVRKQvEwSxd6hnuQdDoXJ5qpGsvVchmESuy6s9MPcd + +# 2-of-3 multisig +SCRIPT=5221${PK0}21${PK1}21${PK2}53ae + +TMP=/tmp/blocksign.$$ +PORT0=38401 +PORT1=38402 +PORT2=38403 +RPCPORT0=38501 +RPCPORT1=38502 +RPCPORT2=38503 + +echo Setting up nodes... +mkdir -p ${TMP}/node0 +echo "validatepegin=0" > ${TMP}/node0/elements.conf +echo "con_signed_blocks=1" >> ${TMP}/node0/elements.conf +echo "signblockscript=${SCRIPT}" >> ${TMP}/node0/elements.conf +echo "con_max_block_sig_size=150" >> ${TMP}/node0/elements.conf +echo "con_dyna_deploy_start=9999999999" >> ${TMP}/node0/elements.conf +echo "blocksigner=1" >> ${TMP}/node0/elements.conf +echo "debug=federation" >> ${TMP}/node0/elements.conf +echo "debug=net" >> ${TMP}/node0/elements.conf +mkdir -p ${TMP}/node1 +cp ${TMP}/node0/elements.conf \ + ${TMP}/node1/elements.conf +mkdir -p ${TMP}/node2 +cp ${TMP}/node0/elements.conf \ + ${TMP}/node2/elements.conf +echo "elementsregtest.port=${PORT0}" >> ${TMP}/node0/elements.conf +echo "elementsregtest.port=${PORT1}" >> ${TMP}/node1/elements.conf +echo "elementsregtest.port=${PORT2}" >> ${TMP}/node2/elements.conf +echo "elementsregtest.rpcport=${RPCPORT0}" >> ${TMP}/node0/elements.conf +echo "elementsregtest.rpcport=${RPCPORT1}" >> ${TMP}/node1/elements.conf +echo "elementsregtest.rpcport=${RPCPORT2}" >> ${TMP}/node2/elements.conf + +${BIN}d -datadir=${TMP}/node0 -chain=elementsregtest -daemon +${BIN}d -datadir=${TMP}/node1 -chain=elementsregtest -daemon +${BIN}d -datadir=${TMP}/node2 -chain=elementsregtest -daemon +sleep 1 + +echo Importing block-signing keys... +${BIN}-cli -datadir=${TMP}/node0 -chain=elementsregtest createwallet "" >/dev/null +${BIN}-cli -datadir=${TMP}/node0 -chain=elementsregtest importprivkey ${SK0} +${BIN}-cli -datadir=${TMP}/node0 -chain=elementsregtest stop + +${BIN}-cli -datadir=${TMP}/node1 -chain=elementsregtest createwallet "" >/dev/null +${BIN}-cli -datadir=${TMP}/node1 -chain=elementsregtest importprivkey ${SK1} +${BIN}-cli -datadir=${TMP}/node1 -chain=elementsregtest stop + +${BIN}-cli -datadir=${TMP}/node2 -chain=elementsregtest createwallet "" >/dev/null +${BIN}-cli -datadir=${TMP}/node2 -chain=elementsregtest importprivkey ${SK2} +${BIN}-cli -datadir=${TMP}/node2 -chain=elementsregtest stop +sleep 1 + +echo Connecting nodes... +echo "elementsregtest.blocksignnode=${PK1}@localhost:${PORT1}" >> ${TMP}/node0/elements.conf +echo "elementsregtest.blocksignnode=${PK2}@localhost:${PORT2}" >> ${TMP}/node0/elements.conf +echo "elementsregtest.blocksignnode=${PK0}@localhost:${PORT0}" >> ${TMP}/node1/elements.conf +echo "elementsregtest.blocksignnode=${PK2}@localhost:${PORT2}" >> ${TMP}/node1/elements.conf +echo "elementsregtest.blocksignnode=${PK0}@localhost:${PORT0}" >> ${TMP}/node2/elements.conf +echo "elementsregtest.blocksignnode=${PK1}@localhost:${PORT1}" >> ${TMP}/node2/elements.conf + +echo "Watching logs..." +${BIN}d -datadir=${TMP}/node0 -chain=elementsregtest -daemon +${BIN}d -datadir=${TMP}/node1 -chain=elementsregtest -daemon +${BIN}d -datadir=${TMP}/node2 -chain=elementsregtest -daemon + +xtail ${TMP}/node{0,1,2}/elementsregtest/debug.log + +echo "" +echo "Cleaning up..." + +${BIN}-cli -datadir=${TMP}/node0 -chain=elementsregtest stop +${BIN}-cli -datadir=${TMP}/node1 -chain=elementsregtest stop +${BIN}-cli -datadir=${TMP}/node2 -chain=elementsregtest stop +sleep 1 +rm -rf ${TMP} + +echo "Done!" + +# End of File diff --git a/contrib/federation/elements.conf b/contrib/federation/elements.conf new file mode 100644 index 0000000000..df158843c4 --- /dev/null +++ b/contrib/federation/elements.conf @@ -0,0 +1,11 @@ +validatepegin=0 +con_blocksubsidy=5000000000 +con_signed_blocks=1 +signblockscript=52210358e9f8af27053e08243270dc20e2542904561af30b60ad2be4dbc070d5af01ae210217420a47c91a2c9a7f18d6e8d881881cb9118915525041320cb9b379cbe25dc621027cd276ac6111da90f87823f278e601be900e58c1a38690af9b9e22136a9b8d2853ae +con_max_block_sig_size=150 +con_dyna_deploy_start=9999999999 +elementsregtest.port=38233 +elementsregtest.rpcport=38232 +elementsregtest.addnode=vt4ahyjxprgvqrtv42kiqii2yhm6xebmlqkdphjnrxx2hw3r7wjklfad.onion:38233 +elementsregtest.addnode=biojtxr7rfene2ynqwwp7avqoctcn2y6hld5k5ctim3cevamxy4uvoqd.onion:38233 +elementsregtest.addnode=vhi7qknkigewaxgmv7s7exmvklrj2haiqbp7nnq3wxwxeldjc6vvclid.onion:38233 diff --git a/src/Makefile.am b/src/Makefile.am index a29a52eb0d..cd26b0f5f0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -143,6 +143,7 @@ BITCOIN_CORE_H = \ cuckoocache.h \ dbwrapper.h \ dynafed.h \ + federation.h \ flatfile.h \ fs.h \ httprpc.h \ @@ -310,6 +311,7 @@ libbitcoin_server_a_SOURCES = \ consensus/tx_verify.cpp \ dynafed.cpp \ dbwrapper.cpp \ + federation.cpp \ flatfile.cpp \ httprpc.cpp \ httpserver.cpp \ diff --git a/src/federation.cpp b/src/federation.cpp new file mode 100644 index 0000000000..ef046e67a6 --- /dev/null +++ b/src/federation.cpp @@ -0,0 +1,862 @@ +// Copyright (c) 2021 Digital Garage +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include