Skip to content

Commit

Permalink
Merge pull request #484 from rsksmart/transaction_pool
Browse files Browse the repository at this point in the history
Transaction pool
  • Loading branch information
aeidelman authored Mar 5, 2018
2 parents 0443acb + 250f23e commit 1192882
Show file tree
Hide file tree
Showing 56 changed files with 1,351 additions and 1,310 deletions.
12 changes: 5 additions & 7 deletions rskj-core/src/main/java/co/rsk/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class Start {

private final Web3 web3Service;
private final BlockProcessor nodeBlockProcessor;
private final PendingState pendingState;
private final TransactionPool transactionPool;
private final SyncPool.PeerClientFactory peerClientFactory;

public static void main(String[] args) throws Exception {
Expand All @@ -96,7 +96,7 @@ public Start(Rsk rsk,
MessageHandler messageHandler,
TxHandler txHandler,
BlockProcessor nodeBlockProcessor,
PendingState pendingState,
TransactionPool transactionPool,
SyncPool.PeerClientFactory peerClientFactory) {
this.rsk = rsk;
this.udpServer = udpServer;
Expand All @@ -112,7 +112,7 @@ public Start(Rsk rsk,
this.messageHandler = messageHandler;
this.txHandler = txHandler;
this.nodeBlockProcessor = nodeBlockProcessor;
this.pendingState = pendingState;
this.transactionPool = transactionPool;
this.peerClientFactory = peerClientFactory;
}

Expand All @@ -124,9 +124,8 @@ public void startNode(String[] args) throws Exception {
BuildInfo.printInfo();

// this should be the genesis block at this point
pendingState.start(blockchain.getBestBlock());
transactionPool.start(blockchain.getBestBlock());
channelManager.start();
txHandler.start();
messageHandler.start();

rsk.init();
Expand Down Expand Up @@ -194,7 +193,7 @@ private void enableSimulateTxs() {
}

private void enableSimulateTxsEx() {
new TxBuilderEx(rskSystemProperties, rsk, repository, nodeBlockProcessor, pendingState).simulateTxs();
new TxBuilderEx(rskSystemProperties, rsk, repository, nodeBlockProcessor, transactionPool).simulateTxs();
}

private void waitRskSyncDone() throws InterruptedException {
Expand All @@ -216,7 +215,6 @@ public void stop() {
}
rsk.close();
messageHandler.stop();
txHandler.stop();
channelManager.stop();
}

Expand Down
20 changes: 10 additions & 10 deletions rskj-core/src/main/java/co/rsk/core/RskFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import co.rsk.config.RskSystemProperties;
import co.rsk.core.bc.BlockChainImpl;
import co.rsk.core.bc.PendingStateImpl;
import co.rsk.core.bc.TransactionPoolImpl;
import co.rsk.metrics.HashRateCalculator;
import co.rsk.mine.MinerClient;
import co.rsk.mine.MinerServer;
Expand All @@ -44,7 +44,7 @@
import co.rsk.validators.ProofOfWorkRule;
import org.ethereum.config.SystemProperties;
import org.ethereum.core.Blockchain;
import org.ethereum.core.PendingState;
import org.ethereum.core.TransactionPool;
import org.ethereum.core.Repository;
import org.ethereum.core.genesis.BlockChainLoader;
import org.ethereum.datasource.KeyValueDataSource;
Expand Down Expand Up @@ -140,7 +140,7 @@ public TxHandler getTxHandler(RskSystemProperties config, CompositeEthereumListe
@Bean
public Web3 getWeb3(Rsk rsk,
Blockchain blockchain,
PendingState pendingState,
TransactionPool transactionPool,
RskSystemProperties config,
MinerClient minerClient,
MinerServer minerServer,
Expand All @@ -160,7 +160,7 @@ public Web3 getWeb3(Rsk rsk,
return new Web3RskImpl(
rsk,
blockchain,
pendingState,
transactionPool,
config,
minerClient,
minerServer,
Expand Down Expand Up @@ -211,13 +211,13 @@ public BlockChainImpl getBlockchain(BlockChainLoader blockChainLoader) {
}

@Bean
public PendingState getPendingState(org.ethereum.db.BlockStore blockStore,
public TransactionPool getTransactionPool(org.ethereum.db.BlockStore blockStore,
ReceiptStore receiptStore,
org.ethereum.core.Repository repository,
RskSystemProperties config,
ProgramInvokeFactory programInvokeFactory,
@Qualifier("compositeEthereumListener") EthereumListener listener) {
return new PendingStateImpl(
return new TransactionPoolImpl(
blockStore,
receiptStore,
listener,
Expand Down Expand Up @@ -286,21 +286,21 @@ public Wallet getWallet(RskSystemProperties config) {
}

@Bean
public PersonalModule getPersonalModuleWallet(RskSystemProperties config, Rsk rsk, Wallet wallet, PendingState pendingState) {
public PersonalModule getPersonalModuleWallet(RskSystemProperties config, Rsk rsk, Wallet wallet, TransactionPool transactionPool) {
if (wallet == null) {
return new PersonalModuleWalletDisabled();
}

return new PersonalModuleWalletEnabled(config, rsk, wallet, pendingState);
return new PersonalModuleWalletEnabled(config, rsk, wallet, transactionPool);
}

@Bean
public EthModuleWallet getEthModuleWallet(RskSystemProperties config, Rsk rsk, Wallet wallet, PendingState pendingState) {
public EthModuleWallet getEthModuleWallet(RskSystemProperties config, Rsk rsk, Wallet wallet, TransactionPool transactionPool) {
if (wallet == null) {
return new EthModuleWalletDisabled();
}

return new EthModuleWalletEnabled(config, rsk, wallet, pendingState);
return new EthModuleWalletEnabled(config, rsk, wallet, transactionPool);
}

@Bean
Expand Down
6 changes: 3 additions & 3 deletions rskj-core/src/main/java/co/rsk/core/RskImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import co.rsk.config.RskSystemProperties;
import co.rsk.net.NodeBlockProcessor;
import org.ethereum.core.Blockchain;
import org.ethereum.core.PendingState;
import org.ethereum.core.TransactionPool;
import org.ethereum.facade.EthereumImpl;
import org.ethereum.listener.CompositeEthereumListener;
import org.ethereum.net.server.ChannelManager;
Expand All @@ -39,7 +39,7 @@ public class RskImpl extends EthereumImpl implements Rsk {
public RskImpl(
ChannelManager channelManager,
PeerServer peerServer,
PendingState pendingState,
TransactionPool transactionPool,
RskSystemProperties config,
CompositeEthereumListener compositeEthereumListener,
NodeBlockProcessor nodeBlockProcessor,
Expand All @@ -49,7 +49,7 @@ public RskImpl(
config,
channelManager,
peerServer,
pendingState,
transactionPool,
compositeEthereumListener,
blockchain
);
Expand Down
18 changes: 9 additions & 9 deletions rskj-core/src/main/java/co/rsk/core/SnapshotManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.google.common.annotations.VisibleForTesting;
import org.ethereum.core.Block;
import org.ethereum.core.Blockchain;
import org.ethereum.core.PendingState;
import org.ethereum.core.TransactionPool;
import org.ethereum.db.BlockStore;

import java.util.ArrayList;
Expand All @@ -42,7 +42,7 @@ public int takeSnapshot(Blockchain blockchain) {
public boolean resetSnapshots(Blockchain blockchain) {
this.snapshots = new ArrayList<>();

PendingState pendingState = blockchain.getPendingState();
TransactionPool transactionPool = blockchain.getTransactionPool();

long bestNumber = blockchain.getBestBlock().getNumber();

Expand All @@ -54,10 +54,10 @@ public boolean resetSnapshots(Blockchain blockchain) {
blockchain.setStatus(block, difficulty);

// To clean pending state, first process the fork
blockchain.getPendingState().processBest(block);
blockchain.getTransactionPool().processBest(block);
// then, clear any reverted transaction
pendingState.clearPendingState(pendingState.getAllPendingTransactions());
pendingState.clearWire(pendingState.getWireTransactions());
transactionPool.removeTransactions(transactionPool.getPendingTransactions());
transactionPool.removeTransactions(transactionPool.getQueuedTransactions());

// Remove removed blocks from store
for (long nb = blockchain.getBestBlock().getNumber() + 1; nb <= bestNumber; nb++) {
Expand All @@ -78,7 +78,7 @@ public boolean revertToSnapshot(Blockchain blockchain, int snapshotId) {

this.snapshots = newSnapshots;

PendingState pendingState = blockchain.getPendingState();
TransactionPool transactionPool = blockchain.getTransactionPool();

long currentBestBlockNumber = blockchain.getBestBlock().getNumber();

Expand All @@ -94,10 +94,10 @@ public boolean revertToSnapshot(Blockchain blockchain, int snapshotId) {
blockchain.setStatus(block, difficulty);

// To clean pending state, first process the fork
blockchain.getPendingState().processBest(block);
blockchain.getTransactionPool().processBest(block);
// then, clear any reverted transaction
pendingState.clearPendingState(pendingState.getAllPendingTransactions());
pendingState.clearWire(pendingState.getWireTransactions());
transactionPool.removeTransactions(transactionPool.getPendingTransactions());
transactionPool.removeTransactions(transactionPool.getQueuedTransactions());

// Remove removed blocks from store
for (long nb = blockchain.getBestBlock().getNumber() + 1; nb <= currentBestBlockNumber; nb++) {
Expand Down
15 changes: 7 additions & 8 deletions rskj-core/src/main/java/co/rsk/core/bc/BlockChainImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class BlockChainImpl implements Blockchain {
private final Repository repository;
private final BlockStore blockStore;
private final ReceiptStore receiptStore;
private PendingState pendingState;
private TransactionPool transactionPool;
private EthereumListener listener;
private final AdminInfo adminInfo;
private BlockValidator blockValidator;
Expand All @@ -100,7 +100,7 @@ public BlockChainImpl(RskSystemProperties config,
Repository repository,
BlockStore blockStore,
ReceiptStore receiptStore,
PendingState pendingState,
TransactionPool transactionPool,
EthereumListener listener,
AdminInfo adminInfo,
BlockValidator blockValidator) {
Expand All @@ -112,20 +112,19 @@ public BlockChainImpl(RskSystemProperties config,
this.adminInfo = adminInfo;
this.blockValidator = blockValidator;
this.blockExecutor = new BlockExecutor(config, repository, receiptStore, blockStore, listener);
this.pendingState = pendingState;
this.transactionPool = transactionPool;
}

@Override
public Repository getRepository() {
return repository;
}

@Override
public PendingState getPendingState() { return pendingState; }
public TransactionPool getTransactionPool() { return transactionPool; }

// circular dependency
public void setPendingState(PendingState pendingState) {
this.pendingState = pendingState;
public void setTransactionPool(TransactionPool transactionPool) {
this.transactionPool = transactionPool;
}

@Override
Expand Down Expand Up @@ -518,7 +517,7 @@ private void saveReceipts(Block block, BlockResult result) {
}

private void processBest(final Block block) {
EventDispatchThread.invokeLater(() -> pendingState.processBest(block));
EventDispatchThread.invokeLater(() -> transactionPool.processBest(block));
}

private void onBlock(Block block, BlockResult result) {
Expand Down
Loading

0 comments on commit 1192882

Please sign in to comment.