Skip to content

Commit 35d57d7

Browse files
carvercburgdorf
authored andcommitted
Support basic VM calls in BaseChain & txpool fixup
1 parent 9b16a16 commit 35d57d7

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed

evm/chains/base.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@ def get_chaindb_class(cls) -> Type[BaseChainDB]:
124124
raise NotImplementedError("Chain classes must implement this method")
125125

126126
@classmethod
127-
@abstractmethod
128127
def get_vm_configuration(cls) -> Tuple[Tuple[int, Type['BaseVM']], ...]:
129-
raise NotImplementedError("Chain classes must implement this method")
128+
return cls.vm_configuration
130129

131130
#
132131
# Chain API
@@ -149,9 +148,11 @@ def from_genesis_header(cls,
149148
#
150149
# VM API
151150
#
152-
@abstractmethod
153-
def get_vm_class(self, header: BlockHeader=None) -> Type['BaseVM']:
154-
raise NotImplementedError("Chain classes must implement this method")
151+
def get_vm_class(self, header: BlockHeader) -> Type['BaseVM']:
152+
"""
153+
Returns the VM instance for the given block number.
154+
"""
155+
return self.get_vm_class_for_block_number(header.block_number)
155156

156157
@abstractmethod
157158
def get_vm(self, header: BlockHeader=None) -> 'BaseVM':
@@ -310,10 +311,6 @@ def get_chaindb_class(cls) -> Type[BaseChainDB]:
310311
raise AttributeError("`chaindb_class` not set")
311312
return cls.chaindb_class
312313

313-
@classmethod
314-
def get_vm_configuration(cls) -> Tuple[Tuple[int, Type['BaseVM']], ...]:
315-
return cls.vm_configuration
316-
317314
#
318315
# Chain API
319316
#
@@ -371,13 +368,6 @@ def from_genesis_header(cls,
371368
#
372369
# VM API
373370
#
374-
def get_vm_class(self, at_header: BlockHeader=None) -> Type['BaseVM']:
375-
"""
376-
Returns the VM instance for the given block number.
377-
"""
378-
header = self.ensure_header(at_header)
379-
return self.get_vm_class_for_block_number(header.block_number)
380-
381371
def get_vm(self, at_header: BlockHeader=None) -> 'BaseVM':
382372
"""
383373
Returns the VM instance for the given block number.

trinity/plugins/builtin/tx_pool/plugin.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
)
99
from evm.chains.mainnet import (
1010
BYZANTIUM_MAINNET_BLOCK,
11-
MainnetChain,
11+
BaseMainnetChain,
1212
)
1313
from evm.chains.ropsten import (
1414
BYZANTIUM_ROPSTEN_BLOCK,
15-
RopstenChain,
15+
BaseRopstenChain,
1616
)
1717

1818
from p2p.cancel_token import (
@@ -71,14 +71,14 @@ def should_start(self) -> bool:
7171
return all((self.peer_pool is not None, self.chain is not None, self.is_enabled))
7272

7373
def start(self, context: PluginContext) -> None:
74-
if isinstance(self.chain, MainnetChain):
74+
if isinstance(self.chain, BaseMainnetChain):
7575
validator = DefaultTransactionValidator(self.chain, BYZANTIUM_MAINNET_BLOCK)
76-
elif isinstance(self.chain, RopstenChain):
76+
elif isinstance(self.chain, BaseRopstenChain):
7777
validator = DefaultTransactionValidator(self.chain, BYZANTIUM_ROPSTEN_BLOCK)
7878
else:
7979
# TODO: We could hint the user about e.g. a --tx-pool-no-validation flag to run the
8080
# tx pool without tx validation in this case
81-
raise ValueError("The TxPool plugin does only support MainnetChain or RopstenChain")
81+
raise ValueError("The TxPool plugin only supports MainnetChain or RopstenChain")
8282

8383
tx_pool = TxPool(self.peer_pool, validator, self.cancel_token)
8484
asyncio.ensure_future(tx_pool.run())

trinity/plugins/builtin/tx_pool/validators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def __call__(self, transaction: BaseTransactionFields) -> bool:
4949

5050
@cachetools.func.ttl_cache(maxsize=1024, ttl=300)
5151
def get_appropriate_tx_class(self) -> Type[BaseTransaction]:
52-
current_tx_class = self.chain.get_vm_class().get_transaction_class()
52+
head = self.chain.get_canonical_head()
53+
current_tx_class = self.chain.get_vm_class(head).get_transaction_class()
5354
# If the current head of the chain is still on a fork that is before the currently
5455
# active fork (syncing), ensure that we use the specified initial tx class
5556
if self._is_outdated_tx_class(current_tx_class):

0 commit comments

Comments
 (0)