Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

~2x state_sim speedup via additional caching in get_crosslink_committee #316

Merged
merged 1 commit into from
Jul 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
~2x state_sim speedup via additional caching in get_crosslink_committ…
…ee(...)
  • Loading branch information
tersec committed Jul 10, 2019
commit 8c232fd1acfd1d6b12c474c08dc62961ed3852ce
2 changes: 2 additions & 0 deletions beacon_chain/beacon_node_types.nim
Original file line number Diff line number Diff line change
@@ -209,6 +209,8 @@ type
Table[tuple[a: int, b: Eth2Digest], seq[ValidatorIndex]]
active_validator_indices_cache*:
Table[Epoch, seq[ValidatorIndex]]
start_shard_cache*: Table[Epoch, Shard]
committee_count_cache*: Table[Epoch, uint64]

BlockSlot* = object
## Unique identifier for a particular fork in the block chain - normally,
13 changes: 11 additions & 2 deletions beacon_chain/spec/validator.nim
Original file line number Diff line number Diff line change
@@ -151,11 +151,18 @@ func get_crosslink_committee*(state: BeaconState, epoch: Epoch, shard: Shard,
stateCache.active_validator_indices_cache[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(
stateCache.active_validator_indices_cache[epoch],
get_seed(state, epoch),
(shard + SHARD_COUNT - get_start_shard(state, epoch)) mod SHARD_COUNT,
get_committee_count(state, epoch),
(shard + SHARD_COUNT - stateCache.start_shard_cache[epoch]) mod
SHARD_COUNT,
stateCache.committee_count_cache[epoch],
stateCache
)

@@ -165,6 +172,8 @@ func get_empty_per_epoch_cache*(): StateCache =
initTable[tuple[a: int, b: Eth2Digest], seq[ValidatorIndex]]()
result.active_validator_indices_cache =
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
func get_beacon_proposer_index*(state: BeaconState, stateCache: var StateCache):