Skip to content

Commit

Permalink
Merge pull request #1229 from rsksmart/papyrus-configs
Browse files Browse the repository at this point in the history
Set Papyrus network upgrade activation heights and version name
  • Loading branch information
josedahlquist authored Apr 29, 2020
2 parents 32dbe67 + 9cb289a commit e8c778d
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 26 deletions.
44 changes: 33 additions & 11 deletions rskj-core/src/main/java/co/rsk/peg/BridgeState.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
import co.rsk.bitcoinj.core.UTXO;
import co.rsk.config.BridgeConstants;
import co.rsk.crypto.Keccak256;
import org.ethereum.config.blockchain.upgrades.ActivationConfig;
import org.ethereum.config.blockchain.upgrades.ConsensusRule;
import org.ethereum.util.RLP;
import org.ethereum.util.RLPList;

import javax.annotation.Nullable;
import java.io.IOException;
import java.math.BigInteger;
import java.util.*;
Expand All @@ -41,22 +44,30 @@ public class BridgeState {
private final SortedMap<Keccak256, BtcTransaction> rskTxsWaitingForSignatures;
private final ReleaseRequestQueue releaseRequestQueue;
private final ReleaseTransactionSet releaseTransactionSet;

private BridgeState(int btcBlockchainBestChainHeight, List<UTXO> activeFederationBtcUTXOs,
SortedMap<Keccak256, BtcTransaction> rskTxsWaitingForSignatures, ReleaseRequestQueue releaseRequestQueue, ReleaseTransactionSet releaseTransactionSet) {
private final ActivationConfig.ForBlock activations;

private BridgeState(int btcBlockchainBestChainHeight,
List<UTXO> activeFederationBtcUTXOs,
SortedMap<Keccak256,
BtcTransaction> rskTxsWaitingForSignatures,
ReleaseRequestQueue releaseRequestQueue,
ReleaseTransactionSet releaseTransactionSet,
@Nullable ActivationConfig.ForBlock activations) {
this.btcBlockchainBestChainHeight = btcBlockchainBestChainHeight;
this.activeFederationBtcUTXOs = activeFederationBtcUTXOs;
this.rskTxsWaitingForSignatures = rskTxsWaitingForSignatures;
this.releaseRequestQueue = releaseRequestQueue;
this.releaseTransactionSet = releaseTransactionSet;
this.activations = activations;
}

public BridgeState(int btcBlockchainBestChainHeight, BridgeStorageProvider provider) throws IOException {
public BridgeState(int btcBlockchainBestChainHeight, BridgeStorageProvider provider, ActivationConfig.ForBlock activations) throws IOException {
this(btcBlockchainBestChainHeight,
provider.getNewFederationBtcUTXOs(),
provider.getRskTxsWaitingForSignatures(),
provider.getReleaseRequestQueue(),
provider.getReleaseTransactionSet());
provider.getReleaseTransactionSet(),
activations);
}

public int getBtcBlockchainBestChainHeight() {
Expand Down Expand Up @@ -101,13 +112,19 @@ public byte[] getEncoded() throws IOException {
byte[] rlpBtcBlockchainBestChainHeight = RLP.encodeBigInteger(BigInteger.valueOf(this.btcBlockchainBestChainHeight));
byte[] rlpActiveFederationBtcUTXOs = RLP.encodeElement(BridgeSerializationUtils.serializeUTXOList(activeFederationBtcUTXOs));
byte[] rlpRskTxsWaitingForSignatures = RLP.encodeElement(BridgeSerializationUtils.serializeMap(rskTxsWaitingForSignatures));
byte[] rlpReleaseRequestQueue = RLP.encodeElement(BridgeSerializationUtils.serializeReleaseRequestQueue(releaseRequestQueue));
byte[] rlpReleaseTransactionSet = RLP.encodeElement(BridgeSerializationUtils.serializeReleaseTransactionSet(releaseTransactionSet));
byte[] serializedReleaseRequestQueue = shouldUsePapyrusEncoding(this.activations) ?
BridgeSerializationUtils.serializeReleaseRequestQueueWithTxHash(releaseRequestQueue):
BridgeSerializationUtils.serializeReleaseRequestQueue(releaseRequestQueue);
byte[] rlpReleaseRequestQueue = RLP.encodeElement(serializedReleaseRequestQueue);
byte[] serializedReleaseTransactionSet = shouldUsePapyrusEncoding(this.activations) ?
BridgeSerializationUtils.serializeReleaseTransactionSetWithTxHash(releaseTransactionSet):
BridgeSerializationUtils.serializeReleaseTransactionSet(releaseTransactionSet);
byte[] rlpReleaseTransactionSet = RLP.encodeElement(serializedReleaseTransactionSet);

return RLP.encodeList(rlpBtcBlockchainBestChainHeight, rlpActiveFederationBtcUTXOs, rlpRskTxsWaitingForSignatures, rlpReleaseRequestQueue, rlpReleaseTransactionSet);
}

public static BridgeState create(BridgeConstants bridgeConstants, byte[] data) throws IOException {
public static BridgeState create(BridgeConstants bridgeConstants, byte[] data, @Nullable ActivationConfig.ForBlock activations) throws IOException {
RLPList rlpList = (RLPList)RLP.decode2(data).get(0);

byte[] btcBlockchainBestChainHeightBytes = rlpList.get(0).getRLPData();
Expand All @@ -117,16 +134,17 @@ public static BridgeState create(BridgeConstants bridgeConstants, byte[] data) t
byte[] rskTxsWaitingForSignaturesBytes = rlpList.get(2).getRLPData();
SortedMap<Keccak256, BtcTransaction> rskTxsWaitingForSignatures = BridgeSerializationUtils.deserializeMap(rskTxsWaitingForSignaturesBytes, bridgeConstants.getBtcParams(), false);
byte[] releaseRequestQueueBytes = rlpList.get(3).getRLPData();
ReleaseRequestQueue releaseRequestQueue = new ReleaseRequestQueue(BridgeSerializationUtils.deserializeReleaseRequestQueue(releaseRequestQueueBytes, bridgeConstants.getBtcParams()));
ReleaseRequestQueue releaseRequestQueue = new ReleaseRequestQueue(BridgeSerializationUtils.deserializeReleaseRequestQueue(releaseRequestQueueBytes, bridgeConstants.getBtcParams(), shouldUsePapyrusEncoding(activations)));
byte[] releaseTransactionSetBytes = rlpList.get(4).getRLPData();
ReleaseTransactionSet releaseTransactionSet = BridgeSerializationUtils.deserializeReleaseTransactionSet(releaseTransactionSetBytes, bridgeConstants.getBtcParams());
ReleaseTransactionSet releaseTransactionSet = BridgeSerializationUtils.deserializeReleaseTransactionSet(releaseTransactionSetBytes, bridgeConstants.getBtcParams(), shouldUsePapyrusEncoding(activations));

return new BridgeState(
btcBlockchainBestChainHeight,
btcUTXOs,
rskTxsWaitingForSignatures,
releaseRequestQueue,
releaseTransactionSet
releaseTransactionSet,
activations
);
}

Expand All @@ -138,4 +156,8 @@ private List<String> toStringList(Set<Keccak256> keys) {

return hashes;
}

public static boolean shouldUsePapyrusEncoding(ActivationConfig.ForBlock activations) {
return activations != null && activations.isActive(ConsensusRule.RSKIP146);
}
}
2 changes: 1 addition & 1 deletion rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ public byte[] getStateForBtcReleaseClient() throws IOException {
* @return a BridgeState serialized in RLP
*/
public byte[] getStateForDebugging() throws IOException, BlockStoreException {
BridgeState stateForDebugging = new BridgeState(getBtcBlockchainBestChainHeight(), provider);
BridgeState stateForDebugging = new BridgeState(getBtcBlockchainBestChainHeight(), provider, activations);

return stateForDebugging.getEncoded();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public Map<String, Object> bridgeState() throws IOException, BlockStoreException

byte[] result = bridgeSupport.getStateForDebugging();

BridgeState state = BridgeState.create(bridgeConstants, result);
BridgeState state = BridgeState.create(bridgeConstants, result, null);

return state.stateToMap();
}
Expand Down
3 changes: 2 additions & 1 deletion rskj-core/src/main/resources/config/devnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ blockchain.config {
orchid = 0,
orchid060 = 0,
wasabi100 = 0,
twoToThree = 0
twoToThree = 0,
papyrus200 = 0
},
consensusRules = {
rskip97 = -1 # disable orchid difficulty drop
Expand Down
3 changes: 2 additions & 1 deletion rskj-core/src/main/resources/config/main.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ blockchain.config {
orchid = 729000,
orchid060 = 1052700,
wasabi100 = 1591000,
twoToThree = 2018000
twoToThree = 2018000,
papyrus200 = 2392700
}
}

Expand Down
3 changes: 2 additions & 1 deletion rskj-core/src/main/resources/config/regtest.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ blockchain.config {
orchid = 0,
orchid060 = 0,
wasabi100 = 0,
twoToThree = 0
twoToThree = 0,
papyrus200 = 0
},
consensusRules = {
rskip97 = -1 # disable orchid difficulty drop
Expand Down
3 changes: 2 additions & 1 deletion rskj-core/src/main/resources/config/testnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ blockchain.config {
orchid = 0,
orchid060 = 0,
wasabi100 = 0,
twoToThree = 504000
twoToThree = 504000,
papyrus200 = 863000
},
consensusRules = {
rskip97 = -1, # disable orchid difficulty drop
Expand Down
3 changes: 0 additions & 3 deletions rskj-core/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# disable wasabi+1 consensus rules by default for every network
blockchain.config.hardforkActivationHeights.papyrus200 = -1

blockchain = {
config = {
consensusRules = {
Expand Down
2 changes: 1 addition & 1 deletion rskj-core/src/main/resources/version.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
versionNumber='2.0.0'
modifier="SNAPSHOT"
modifier="PAPYRUS"
4 changes: 2 additions & 2 deletions rskj-core/src/test/java/co/rsk/peg/BridgeStateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public void recreateFromEmptyStorageProvider() throws IOException {
bridgeConstants, config.getActivationConfig().forBlock(0L)
);

BridgeState state = new BridgeState(42, provider);
BridgeState state = new BridgeState(42, provider, null);

BridgeState clone = BridgeState.create(bridgeConstants, state.getEncoded());
BridgeState clone = BridgeState.create(bridgeConstants, state.getEncoded(), null);

Assert.assertNotNull(clone);
Assert.assertEquals(42, clone.getBtcBlockchainBestChainHeight());
Expand Down
7 changes: 6 additions & 1 deletion rskj-core/src/test/java/co/rsk/peg/RskForksBridgeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import co.rsk.trie.TrieStore;
import org.bouncycastle.util.encoders.Hex;
import org.ethereum.config.Constants;
import org.ethereum.config.blockchain.upgrades.ActivationConfig;
import org.ethereum.core.*;
import org.ethereum.crypto.ECKey;
import org.ethereum.db.BlockStore;
Expand Down Expand Up @@ -80,6 +81,9 @@ public void before() {
//keyHoldingRSKs = new ECKey();
co.rsk.core.Coin balance = new co.rsk.core.Coin(new BigInteger("10000000000000000000"));
repository.addBalance(new RskAddress(fedECPrivateKey.getAddress()), balance);

co.rsk.core.Coin bridgeBalance = co.rsk.core.Coin .fromBitcoin(BridgeRegTestConstants.getInstance().getMaxRbtc());
repository.addBalance(PrecompiledContracts.BRIDGE_ADDR, bridgeBalance);
genesis.setStateRoot(repository.getRoot());
genesis.flushRLP();

Expand Down Expand Up @@ -484,7 +488,8 @@ private BridgeState callGetStateForDebuggingTx() throws IOException {

Object[] result = Bridge.GET_STATE_FOR_DEBUGGING.decodeResult(res.getHReturn());

return BridgeState.create(beforeBambooProperties.getNetworkConstants().getBridgeConstants(), (byte[])result[0]);
ActivationConfig.ForBlock activations = beforeBambooProperties.getActivationConfig().forBlock(blockChain.getBestBlock().getNumber());
return BridgeState.create(beforeBambooProperties.getNetworkConstants().getBridgeConstants(), (byte[])result[0], activations);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

public class EthSubscriptionNotificationTest {
private static final Block TEST_BLOCK = new BlockGenerator().createBlock(12, 0);
private static final String TEST_BLOCK_RESULT_JSON = "{\"difficulty\":\"0x20000\",\"extraData\":\"0x00\",\"gasLimit\":\"0x2fefd8\",\"gasUsed\":\"0x0\",\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"miner\":\"0xe94aef644e428941ee0a3741f28d80255fddba7f\",\"number\":\"0xc\",\"parentHash\":\"0xbe5de0c9c661653c979ec457f610444dcd0048007e683b2d04ce05729af56280\",\"receiptsRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"sha3Uncles\":\"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347\",\"stateRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"timestamp\":\"0x1\",\"transactionsRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"hash\":\"0xcbb16dab6cda29b0bc51dd4389d2abb978a33cfb9dce1fe1ac218e719c932712\"}";
private static final String TEST_BLOCK_RESULT_JSON = "{\"difficulty\":\"0x20000\",\"extraData\":\"0x00\",\"gasLimit\":\"0x2fefd8\",\"gasUsed\":\"0x0\",\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"miner\":\"0xe94aef644e428941ee0a3741f28d80255fddba7f\",\"number\":\"0xc\",\"parentHash\":\"0xbe5de0c9c661653c979ec457f610444dcd0048007e683b2d04ce05729af56280\",\"receiptsRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"sha3Uncles\":\"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347\",\"stateRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"timestamp\":\"0x1\",\"transactionsRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"hash\":\"0x35b063d13f7d7b3c13ae508e2c2b3aa7e7ba110d4dda17f3d822ac24b1f952b7\"}";

private JsonRpcSerializer serializer = new JacksonBasedRpcSerializer();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@

package org.ethereum.core.genesis;

import co.rsk.config.TestSystemProperties;
import co.rsk.core.Coin;
import co.rsk.core.RskAddress;
import co.rsk.core.genesis.TestGenesisLoader;
import co.rsk.db.RepositorySnapshot;
import org.ethereum.config.blockchain.upgrades.ActivationConfig;
import org.ethereum.config.blockchain.upgrades.ConsensusRule;
import org.ethereum.core.Blockchain;
import org.ethereum.util.RskTestFactory;
import org.ethereum.vm.DataWord;
import org.ethereum.vm.PrecompiledContracts;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -45,7 +49,16 @@ protected GenesisLoader buildGenesisLoader() {
Blockchain blockchain = objects.getBlockchain();// calls loadBlockchain
RepositorySnapshot repository = objects.getRepositoryLocator().snapshotAt(blockchain.getBestBlock().getHeader());

int genesisAccountKeysSize = 12; // PCCs + test accounts in blockchain_loader_genesis.json
TestSystemProperties testSystemProperties = new TestSystemProperties();
ActivationConfig.ForBlock activations = testSystemProperties.getActivationConfig().forBlock(0);
int enabledPCCs = PrecompiledContracts.GENESIS_ADDRESSES.size();
for (ConsensusRule consensusRule:PrecompiledContracts.CONSENSUS_ENABLED_ADDRESSES.values()) {
if (activations.isActive(consensusRule)) {
enabledPCCs++;
}
}
int testAccountsSize = 3;
int genesisAccountKeysSize = enabledPCCs + testAccountsSize; // PCCs + test accounts in blockchain_loader_genesis.json
Assert.assertEquals(genesisAccountKeysSize, repository.getAccountsKeys().size());

RskAddress daba01 = new RskAddress("dabadabadabadabadabadabadabadabadaba0001");
Expand Down

0 comments on commit e8c778d

Please sign in to comment.