~2x state_sim speedup via additional caching in get_crosslink_committee(...) (#316)
This commit is contained in:
parent
dfa062db7d
commit
7bc2b81e18
|
@ -209,6 +209,8 @@ type
|
||||||
Table[tuple[a: int, b: Eth2Digest], seq[ValidatorIndex]]
|
Table[tuple[a: int, b: Eth2Digest], seq[ValidatorIndex]]
|
||||||
active_validator_indices_cache*:
|
active_validator_indices_cache*:
|
||||||
Table[Epoch, seq[ValidatorIndex]]
|
Table[Epoch, seq[ValidatorIndex]]
|
||||||
|
start_shard_cache*: Table[Epoch, Shard]
|
||||||
|
committee_count_cache*: Table[Epoch, uint64]
|
||||||
|
|
||||||
BlockSlot* = object
|
BlockSlot* = object
|
||||||
## Unique identifier for a particular fork in the block chain - normally,
|
## Unique identifier for a particular fork in the block chain - normally,
|
||||||
|
|
|
@ -151,11 +151,18 @@ func get_crosslink_committee*(state: BeaconState, epoch: Epoch, shard: Shard,
|
||||||
stateCache.active_validator_indices_cache[epoch] =
|
stateCache.active_validator_indices_cache[epoch] =
|
||||||
get_active_validator_indices(state, epoch)
|
get_active_validator_indices(state, epoch)
|
||||||
|
|
||||||
|
if epoch notin stateCache.start_shard_cache:
|
||||||
|
stateCache.start_shard_cache[epoch] = get_start_shard(state, epoch)
|
||||||
|
|
||||||
|
if epoch notin stateCache.committee_count_cache:
|
||||||
|
stateCache.committee_count_cache[epoch] = get_committee_count(state, epoch)
|
||||||
|
|
||||||
compute_committee(
|
compute_committee(
|
||||||
stateCache.active_validator_indices_cache[epoch],
|
stateCache.active_validator_indices_cache[epoch],
|
||||||
get_seed(state, epoch),
|
get_seed(state, epoch),
|
||||||
(shard + SHARD_COUNT - get_start_shard(state, epoch)) mod SHARD_COUNT,
|
(shard + SHARD_COUNT - stateCache.start_shard_cache[epoch]) mod
|
||||||
get_committee_count(state, epoch),
|
SHARD_COUNT,
|
||||||
|
stateCache.committee_count_cache[epoch],
|
||||||
stateCache
|
stateCache
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -165,6 +172,8 @@ func get_empty_per_epoch_cache*(): StateCache =
|
||||||
initTable[tuple[a: int, b: Eth2Digest], seq[ValidatorIndex]]()
|
initTable[tuple[a: int, b: Eth2Digest], seq[ValidatorIndex]]()
|
||||||
result.active_validator_indices_cache =
|
result.active_validator_indices_cache =
|
||||||
initTable[Epoch, seq[ValidatorIndex]]()
|
initTable[Epoch, seq[ValidatorIndex]]()
|
||||||
|
result.start_shard_cache = initTable[Epoch, Shard]()
|
||||||
|
result.committee_count_cache = initTable[Epoch, uint64]()
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.0/specs/core/0_beacon-chain.md#get_beacon_proposer_index
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.0/specs/core/0_beacon-chain.md#get_beacon_proposer_index
|
||||||
func get_beacon_proposer_index*(state: BeaconState, stateCache: var StateCache):
|
func get_beacon_proposer_index*(state: BeaconState, stateCache: var StateCache):
|
||||||
|
|
Loading…
Reference in New Issue