use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class GasPriceTracker method onBlock.
@Override
public synchronized void onBlock(Block block, List<TransactionReceipt> receipts) {
logger.trace("Start onBlock");
defaultPrice = block.getMinimumGasPrice();
for (Transaction tx : block.getTransactionsList()) {
onTransaction(tx);
}
logger.trace("End onBlock");
}
use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class BridgePerformanceTestCase method executeAndAverage.
protected ExecutionStats executeAndAverage(String name, int times, ABIEncoder abiEncoder, BridgeStorageProviderInitializer storageInitializer, TxBuilder txBuilder, HeightProvider heightProvider, ExecutionStats stats, ResultCallback resultCallback, PostInitCallback postInitCallback) throws VMException {
EnvironmentBuilder environmentBuilder = new EnvironmentBuilder() {
private Bridge bridge;
private RepositoryTrackWithBenchmarking benchmarkerTrack;
private BridgeStorageProvider storageProvider;
private TrieStore createTrieStore() {
return new TrieStoreImpl(new HashMapDB());
}
@Override
public Environment build(int executionIndex, TxBuilder txBuilder, int height) throws VMException {
TrieStore trieStore = createTrieStore();
Trie trie = new Trie(trieStore);
benchmarkerTrack = new RepositoryTrackWithBenchmarking(trieStore, trie);
Repository repository = benchmarkerTrack.startTracking();
storageProvider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, bridgeConstants, activationConfig.forBlock((long) executionIndex));
BtcBlockStore btcBlockStore = btcBlockStoreFactory.newInstance(repository, bridgeConstants, storageProvider, activationConfig.forBlock((long) executionIndex));
storageInitializer.initialize(storageProvider, repository, executionIndex, btcBlockStore);
repository.addBalance(PrecompiledContracts.BRIDGE_ADDR, co.rsk.core.Coin.fromBitcoin(Coin.COIN.multiply(21_000_000L)));
try {
storageProvider.save();
} catch (Exception e) {
throw new RuntimeException("Error trying to save the storage after initialization", e);
}
repository.commit();
benchmarkerTrack.commit();
benchmarkerTrack = new RepositoryTrackWithBenchmarking(trieStore, benchmarkerTrack.getTrie());
List<LogInfo> logs = new ArrayList<>();
// TODO: This was commented to make registerBtcCoinbaseTransactionTest & getBtcTransactionConfirmationTest work.
// Cache is not being populated.
// Factory btcBlockStoreFactory = new RepositoryBtcBlockStoreWithCache.Factory(
// constants.getBridgeConstants().getBtcParams());
BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(btcBlockStoreFactory, constants.getBridgeConstants(), activationConfig);
bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, bridgeSupportFactory);
BlockChainBuilder blockChainBuilder = new BlockChainBuilder();
Blockchain blockchain = blockChainBuilder.ofSize(height);
Transaction tx = txBuilder.build(executionIndex);
bridge.init(tx, blockchain.getBestBlock(), benchmarkerTrack, blockChainBuilder.getBlockStore(), null, logs);
// Execute a random method so that bridge support initialization
// does its initial writes to the repo for e.g. genesis block,
// federation, etc, etc. and we don't get
// those recorded in the actual execution.
boolean oldLocalCall = tx.isLocalCallTransaction();
tx.setLocalCallTransaction(true);
bridge.execute(Bridge.GET_FEDERATION_SIZE.encode());
tx.setLocalCallTransaction(oldLocalCall);
benchmarkerTrack.getStatistics().clear();
Environment environment = new Environment() {
@Override
public PrecompiledContracts.PrecompiledContract getContract() {
return bridge;
}
@Override
public BenchmarkedRepository getBenchmarkedRepository() {
return benchmarkerTrack;
}
@Override
public void finalise() {
benchmarkerTrack.commit();
}
};
if (postInitCallback != null) {
postInitCallback.afterInit(environment);
}
return environment;
}
};
return super.executeAndAverage(name, times, environmentBuilder, abiEncoder, txBuilder, heightProvider, stats, resultCallback);
}
use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class BridgeEventLoggerImplTest method logUpdateCollectionsAfterRskip146HardFork.
@Test
public void logUpdateCollectionsAfterRskip146HardFork() {
when(activations.isActive(ConsensusRule.RSKIP146)).thenReturn(true);
// Setup Rsk transaction
Transaction tx = mock(Transaction.class);
RskAddress sender = mock(RskAddress.class);
when(sender.toString()).thenReturn("0x0000000000000000000000000000000000000001");
when(tx.getSender()).thenReturn(sender);
// Act
eventLogger.logUpdateCollections(tx);
commonAssertLogs(eventLogs);
assertTopics(1, eventLogs);
assertEvent(eventLogs, 0, BridgeEvents.UPDATE_COLLECTIONS.getEvent(), new Object[] {}, new Object[] { tx.getSender().toString() });
}
use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class BridgeEventLoggerImplTest method logUpdateCollectionsBeforeRskip146HardFork.
@Test
public void logUpdateCollectionsBeforeRskip146HardFork() {
when(activations.isActive(ConsensusRule.RSKIP146)).thenReturn(false);
// Setup Rsk transaction
Transaction tx = mock(Transaction.class);
RskAddress sender = mock(RskAddress.class);
when(sender.toString()).thenReturn("0x0000000000000000000000000000000000000001");
when(tx.getSender()).thenReturn(sender);
// Act
eventLogger.logUpdateCollections(tx);
commonAssertLogs(eventLogs);
assertTopics(1, eventLogs);
LogInfo logResult = eventLogs.get(0);
List<DataWord> topics = Collections.singletonList(Bridge.UPDATE_COLLECTIONS_TOPIC);
for (int i = 0; i < topics.size(); i++) {
Assert.assertEquals(topics.get(i), logResult.getTopics().get(i));
}
// Assert log data
byte[] encodedData = RLP.encodeElement(tx.getSender().getBytes());
Assert.assertArrayEquals(encodedData, logResult.getData());
}
use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class DslFilesTest method runCreate01Resource.
@Test
public void runCreate01Resource() throws FileNotFoundException, DslProcessorException {
DslParser parser = DslParser.fromResource("dsl/create01.txt");
World world = new World();
WorldDslProcessor processor = new WorldDslProcessor(world);
processor.processCommands(parser);
Transaction transaction = world.getTransactionByName("tx01");
Assert.assertNotNull(transaction);
TransactionInfo txinfo = world.getBlockChain().getTransactionInfo(transaction.getHash().getBytes());
Assert.assertNotNull(txinfo);
BigInteger gasUsed = BigIntegers.fromUnsignedByteArray(txinfo.getReceipt().getGasUsed());
Assert.assertNotEquals(BigInteger.ZERO, gasUsed);
// According to TestRPC and geth, the gas used is 0x010c2d
Assert.assertEquals(BigIntegers.fromUnsignedByteArray(Hex.decode("010c2d")), gasUsed);
}
Aggregations