Skip to content

Commit

Permalink
add signature cache to EthModuleWalletEnabled class
Browse files Browse the repository at this point in the history
  • Loading branch information
casiojapi committed Feb 9, 2024
1 parent 857c5ea commit 297cf4b
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion rskj-core/src/main/java/co/rsk/RskContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,7 @@ private EthModuleWallet getEthModuleWallet() {
if (wallet == null) {
ethModuleWallet = new EthModuleWalletDisabled();
} else {
ethModuleWallet = new EthModuleWalletEnabled(wallet, transactionPool);
ethModuleWallet = new EthModuleWalletEnabled(wallet, getTransactionPool(), getReceivedTxSignatureCache());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@

import co.rsk.core.RskAddress;
import org.bouncycastle.util.BigIntegers;
import org.ethereum.core.Account;
import org.ethereum.core.Transaction;
import org.ethereum.core.TransactionPool;
import org.ethereum.core.*;
import org.ethereum.crypto.ECKey;
import org.ethereum.crypto.HashUtil;
import org.ethereum.crypto.signature.ECDSASignature;
Expand All @@ -43,13 +41,14 @@
public class EthModuleWalletEnabled implements EthModuleWallet {

private static final Logger LOGGER = LoggerFactory.getLogger("web3");

private final Wallet wallet;
private final TransactionPool transactionPool;
private final SignatureCache signatureCache;

public EthModuleWalletEnabled(Wallet wallet, TransactionPool transactionPool) {
public EthModuleWalletEnabled(Wallet wallet, TransactionPool transactionPool, SignatureCache signatureCache) {
this.wallet = wallet;
this.transactionPool = transactionPool;
this.signatureCache = signatureCache;
}

@Override
Expand Down Expand Up @@ -101,7 +100,7 @@ public List<Transaction> ethPendingTransactions() {
List<Transaction> pendingTxs = transactionPool.getPendingTransactions();
List<String> managedAccounts = Arrays.asList(accounts());
return pendingTxs.stream()
.filter(tx -> managedAccounts.contains(tx.getSender().toJsonString()))
.filter(tx -> managedAccounts.contains(tx.getSender(signatureCache).toJsonString()))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ private Web3Impl internalCreateEnvironment(Blockchain blockchain,
EthModule ethModule = new EthModule(
config.getNetworkConstants().getBridgeConstants(), config.getNetworkConstants().getChainId(), blockchain, transactionPool,
reversibleTransactionExecutor1, new ExecutionBlockRetriever(blockchain, null, null),
repositoryLocator, new EthModuleWalletEnabled(wallet, transactionPool), transactionModule,
repositoryLocator, new EthModuleWalletEnabled(wallet, transactionPool, signatureCache), transactionModule,
new BridgeSupportFactory(
btcBlockStoreFactory, config.getNetworkConstants().getBridgeConstants(),
config.getActivationConfig(), signatureCache),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ void testEthPendingTransactionsWithNoTransactions() {
void pendingTransactionsWithMultipleManagedAccounts() {
Wallet wallet = mock(Wallet.class);
TransactionPool transactionPoolMock = mock(TransactionPool.class);
EthModuleWalletEnabled ethModuleWallet = new EthModuleWalletEnabled(wallet, transactionPoolMock);
EthModuleWalletEnabled ethModuleWallet = new EthModuleWalletEnabled(wallet, transactionPoolMock, signatureCache);
ExecutionBlockRetriever retriever = mock(ExecutionBlockRetriever.class);
Blockchain blockchain = mock(Blockchain.class);
ReversibleTransactionExecutor reversibleTransactionExecutor = mock(ReversibleTransactionExecutor.class);
Expand Down Expand Up @@ -814,7 +814,7 @@ void pendingTransactionsWithMultipleManagedAccounts() {
void pendingTransactionsWithNoManagedAccounts() {
Wallet wallet = mock(Wallet.class);
TransactionPool transactionPoolMock = mock(TransactionPool.class);
EthModuleWalletEnabled ethModuleWallet = new EthModuleWalletEnabled(wallet, transactionPoolMock);
EthModuleWalletEnabled ethModuleWallet = new EthModuleWalletEnabled(wallet, transactionPoolMock, signatureCache);
ExecutionBlockRetriever retriever = mock(ExecutionBlockRetriever.class);
Blockchain blockchain = mock(Blockchain.class);
ReversibleTransactionExecutor reversibleTransactionExecutor = mock(ReversibleTransactionExecutor.class);
Expand Down Expand Up @@ -877,7 +877,7 @@ private Transaction createMockTransaction(String fromAddress) {
Transaction transaction = mock(Transaction.class);
RskAddress address = new RskAddress(fromAddress);
System.out.println("mock address: " + address);
when(transaction.getSender()).thenReturn(address);
when(transaction.getSender(any(SignatureCache.class))).thenReturn(address);

byte[] mockHashBytes = new byte[32];
Arrays.fill(mockHashBytes, (byte) 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ private Web3Impl createWeb3() {
EthModule ethModule = new EthModule(
config.getNetworkConstants().getBridgeConstants(), config.getNetworkConstants().getChainId(), blockChain, transactionPool,
null, new ExecutionBlockRetriever(blockChain, null, null),
null, new EthModuleWalletEnabled(wallet, transactionPool), null,
null, new EthModuleWalletEnabled(wallet, transactionPool, signatureCache), null,
new BridgeSupportFactory(
null, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig(), new BlockTxSignatureCache(new ReceivedTxSignatureCache())),
config.getGasEstimationCap(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ private static Web3Impl createWeb3(PeerScoringManager peerScoringManager) {
EthModule em = new EthModule(
config.getNetworkConstants().getBridgeConstants(), config.getNetworkConstants().getChainId(), world.getBlockChain(), null,
null, new ExecutionBlockRetriever(world.getBlockChain(), null, null),
null, new EthModuleWalletEnabled(wallet, world.getTransactionPool()), null,
null, new EthModuleWalletEnabled(wallet, world.getTransactionPool(), world.getBlockTxSignatureCache()), null,
new BridgeSupportFactory(
null, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig(), new BlockTxSignatureCache(new ReceivedTxSignatureCache())),
config.getGasEstimationCap(),
Expand Down
6 changes: 3 additions & 3 deletions rskj-core/src/test/java/org/ethereum/rpc/Web3ImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2684,7 +2684,7 @@ private Web3Impl createWeb3(SimpleEthereum eth, PeerServer peerServer) {
EthModule ethModule = new EthModule(
config.getNetworkConstants().getBridgeConstants(), config.getNetworkConstants().getChainId(), blockchain, transactionPool,
null, new ExecutionBlockRetriever(blockchain, null, null),
null, new EthModuleWalletEnabled(wallet, transactionPool), null,
null, new EthModuleWalletEnabled(wallet, transactionPool, signatureCache), null,
new BridgeSupportFactory(
null, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig(), signatureCache),
config.getGasEstimationCap(),
Expand Down Expand Up @@ -2801,7 +2801,7 @@ private Web3Impl createWeb3(
TransactionGateway transactionGateway = new TransactionGateway(new SimpleChannelManager(), transactionPool);
EthModule ethModule = new EthModule(
config.getNetworkConstants().getBridgeConstants(), config.getNetworkConstants().getChainId(), blockchain, transactionPool, executor,
new ExecutionBlockRetriever(blockchain, null, null), repositoryLocator, new EthModuleWalletEnabled(wallet, transactionPool),
new ExecutionBlockRetriever(blockchain, null, null), repositoryLocator, new EthModuleWalletEnabled(wallet, transactionPool, signatureCache),
new EthModuleTransactionBase(config.getNetworkConstants(), wallet, transactionPool, transactionGateway),
new BridgeSupportFactory(
null, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig(), signatureCache),
Expand Down Expand Up @@ -2865,7 +2865,7 @@ private Web3Impl createWeb3CallNoReturn(
EthModule ethModule = new EthModule(
config.getNetworkConstants().getBridgeConstants(), config.getNetworkConstants().getChainId(), blockchain, transactionPool, executor,
new ExecutionBlockRetriever(blockchain, null, null), repositoryLocator,
new EthModuleWalletEnabled(wallet, transactionPool),
new EthModuleWalletEnabled(wallet, transactionPool, signatureCache),
new EthModuleTransactionBase(config.getNetworkConstants(), wallet, transactionPool, null),
new BridgeSupportFactory(
null, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig(), signatureCache),
Expand Down

0 comments on commit 297cf4b

Please sign in to comment.