Search in sources :

Example 1 with CoinbaseInformation

use of co.rsk.peg.bitcoin.CoinbaseInformation in project rskj by rsksmart.

the class BridgeStorageProviderTest method setCoinBaseInformation_before_RSKIP143.

@Test
public void setCoinBaseInformation_before_RSKIP143() {
    Repository repository = mock(Repository.class);
    Sha256Hash hash = Sha256Hash.ZERO_HASH;
    BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork);
    assertNull(provider.getCoinbaseInformation(hash));
    CoinbaseInformation coinbaseInformation = new CoinbaseInformation(Sha256Hash.ZERO_HASH);
    provider.setCoinbaseInformation(hash, coinbaseInformation);
    assertNull(provider.getCoinbaseInformation(hash));
}
Also used : Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) CoinbaseInformation(co.rsk.peg.bitcoin.CoinbaseInformation) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with CoinbaseInformation

use of co.rsk.peg.bitcoin.CoinbaseInformation in project rskj by rsksmart.

the class BridgeStorageProviderTest method getCoinBaseInformation_before_RSKIP143.

@Test
public void getCoinBaseInformation_before_RSKIP143() {
    Repository repository = mock(Repository.class);
    Sha256Hash hash = Sha256Hash.ZERO_HASH;
    BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork);
    CoinbaseInformation result = provider.getCoinbaseInformation(hash);
    assertNull(result);
    verify(repository, never()).getStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromLongString("coinbaseInformation-" + hash.toString()));
}
Also used : Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) CoinbaseInformation(co.rsk.peg.bitcoin.CoinbaseInformation) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with CoinbaseInformation

use of co.rsk.peg.bitcoin.CoinbaseInformation in project rskj by rsksmart.

the class BridgeStorageProviderTest method getCoinBaseInformation_after_RSKIP143.

@Test
public void getCoinBaseInformation_after_RSKIP143() {
    Repository repository = mock(Repository.class);
    Sha256Hash hash = Sha256Hash.ZERO_HASH;
    CoinbaseInformation coinbaseInformation = new CoinbaseInformation(Sha256Hash.ZERO_HASH);
    when(repository.getStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromLongString("coinbaseInformation-" + hash.toString()))).thenReturn(BridgeSerializationUtils.serializeCoinbaseInformation(coinbaseInformation));
    BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, config.getNetworkConstants().getBridgeConstants(), activationsAllForks);
    CoinbaseInformation result = provider.getCoinbaseInformation(hash);
    assertEquals(coinbaseInformation.getWitnessMerkleRoot(), result.getWitnessMerkleRoot());
}
Also used : Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) CoinbaseInformation(co.rsk.peg.bitcoin.CoinbaseInformation) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with CoinbaseInformation

use of co.rsk.peg.bitcoin.CoinbaseInformation in project rskj by rsksmart.

the class BridgeSupport method isBlockMerkleRootValid.

@VisibleForTesting
protected boolean isBlockMerkleRootValid(Sha256Hash merkleRoot, BtcBlock blockHeader) {
    boolean isValid = false;
    if (blockHeader.getMerkleRoot().equals(merkleRoot)) {
        logger.trace("block merkle root is valid");
        isValid = true;
    } else {
        if (activations.isActive(ConsensusRule.RSKIP143)) {
            CoinbaseInformation coinbaseInformation = provider.getCoinbaseInformation(blockHeader.getHash());
            if (coinbaseInformation == null) {
                logger.trace("coinbase information for block {} is not yet registered", blockHeader.getHash());
            }
            isValid = coinbaseInformation != null && coinbaseInformation.getWitnessMerkleRoot().equals(merkleRoot);
            logger.trace("witness merkle root is {} valid", (isValid ? "" : "NOT"));
        } else {
            logger.trace("RSKIP143 is not active, avoid checking witness merkle root");
        }
    }
    return isValid;
}
Also used : CoinbaseInformation(co.rsk.peg.bitcoin.CoinbaseInformation) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with CoinbaseInformation

use of co.rsk.peg.bitcoin.CoinbaseInformation in project rskj by rsksmart.

the class BridgeStorageProvider method getCoinbaseInformation.

public CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash) {
    if (!activations.isActive(RSKIP143)) {
        return null;
    }
    if (coinbaseInformationMap == null) {
        coinbaseInformationMap = new HashMap<>();
    }
    if (coinbaseInformationMap.containsKey(blockHash)) {
        return coinbaseInformationMap.get(blockHash);
    }
    CoinbaseInformation coinbaseInformation = safeGetFromRepository(getStorageKeyForCoinbaseInformation(blockHash), BridgeSerializationUtils::deserializeCoinbaseInformation);
    coinbaseInformationMap.put(blockHash, coinbaseInformation);
    return coinbaseInformation;
}
Also used : CoinbaseInformation(co.rsk.peg.bitcoin.CoinbaseInformation)

Aggregations

CoinbaseInformation (co.rsk.peg.bitcoin.CoinbaseInformation)22 Test (org.junit.Test)18 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)17 Repository (org.ethereum.core.Repository)16 MutableRepository (org.ethereum.db.MutableRepository)16 PeginInstructionsProvider (co.rsk.peg.pegininstructions.PeginInstructionsProvider)11 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)11 Block (org.ethereum.core.Block)11 BtcLockSenderProvider (co.rsk.peg.btcLockSender.BtcLockSenderProvider)9 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 Script (co.rsk.bitcoinj.script.Script)5 BigInteger (java.math.BigInteger)5 MerkleBranch (co.rsk.peg.bitcoin.MerkleBranch)3 SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)3 Transaction (org.ethereum.core.Transaction)3 InternalTransaction (org.ethereum.vm.program.InternalTransaction)3 RskAddress (co.rsk.core.RskAddress)2 PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation (co.rsk.peg.PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation)2 PegTestUtils.createBaseRedeemScriptThatSpendsFromTheFederation (co.rsk.peg.PegTestUtils.createBaseRedeemScriptThatSpendsFromTheFederation)2