Search in sources :

Example 21 with Transaction

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");
}
Also used : RemascTransaction(co.rsk.remasc.RemascTransaction) Transaction(org.ethereum.core.Transaction)

Example 22 with Transaction

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);
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) LogInfo(org.ethereum.vm.LogInfo) Blockchain(org.ethereum.core.Blockchain) BtcBlockStore(co.rsk.bitcoinj.store.BtcBlockStore) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) RepositoryTrackWithBenchmarking(co.rsk.db.RepositoryTrackWithBenchmarking) VMException(org.ethereum.vm.exception.VMException) BenchmarkedRepository(co.rsk.db.BenchmarkedRepository) Repository(org.ethereum.core.Repository) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) InternalTransaction(org.ethereum.vm.program.InternalTransaction) Transaction(org.ethereum.core.Transaction) Trie(co.rsk.trie.Trie)

Example 23 with Transaction

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() });
}
Also used : CallTransaction(org.ethereum.core.CallTransaction) Transaction(org.ethereum.core.Transaction) RskAddress(co.rsk.core.RskAddress) Test(org.junit.Test)

Example 24 with Transaction

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());
}
Also used : LogInfo(org.ethereum.vm.LogInfo) CallTransaction(org.ethereum.core.CallTransaction) Transaction(org.ethereum.core.Transaction) RskAddress(co.rsk.core.RskAddress) DataWord(org.ethereum.vm.DataWord) Test(org.junit.Test)

Example 25 with Transaction

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);
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Transaction(org.ethereum.core.Transaction) DslParser(co.rsk.test.dsl.DslParser) TransactionInfo(org.ethereum.db.TransactionInfo) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Aggregations

Transaction (org.ethereum.core.Transaction)257 Test (org.junit.Test)166 Block (org.ethereum.core.Block)73 RskAddress (co.rsk.core.RskAddress)69 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)57 InternalTransaction (org.ethereum.vm.program.InternalTransaction)57 SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)39 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)39 BigInteger (java.math.BigInteger)38 ArrayList (java.util.ArrayList)38 Repository (org.ethereum.core.Repository)35 JsonNode (com.fasterxml.jackson.databind.JsonNode)32 ECKey (org.ethereum.crypto.ECKey)30 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)29 Keccak256 (co.rsk.crypto.Keccak256)28 Account (org.ethereum.core.Account)26 World (co.rsk.test.World)23 DslParser (co.rsk.test.dsl.DslParser)23 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)23 MutableRepository (org.ethereum.db.MutableRepository)22