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));
}
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()));
}
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());
}
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;
}
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;
}
Aggregations