Skip to content
Merged
Show file tree
Hide file tree
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
44 changes: 15 additions & 29 deletions lodestar_chain/state/activeState.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
var exports = module.exports = {};

var PartialCrossLinks = require('./partialCrosslinks.js');
var RecentProposerRecord = require('./recentProposerRecord.js');
var AttestationRecord = require('./attestationRecord.js');

class ActiveState {

var fields = {
// Block height
'height':'int64',
// Global RANDAO beacon state
'randao':'bytes32',
// Which validators have made FFG votes this epoch (as a bitfield)
'ffg_voter_bitfield': 'bytes',
// Block attesters in the last epoch
'recent_attesters': ['int24'],
// Storing data about crosslinks-in-progress attempted in this epoch
'partial_crosslinks': [PartialCrossLinks],
// Total number of skips (used to determine minimum timestamp)
'total_skip_count': 'int64',
// Block proposer in the last epoch
'recent_proposers': [RecentProposerRecord]
// Attestations that have not yet been processed
'pending_attestations': [AttestationRecord],
// Most recent 2 * CYCLE_LENGTH block hashes, older to newer
'recent_block_hashes': ['hash32']
};

var defaults = {
'height': 0,
'randao': 'x00'.repeat(32),
'ffg_voter_bitfield': '',
'recent_attesters': [],
'partial_crosslinks': [],
'total_skip_count': 0,
'recent_proposers': []
'pending_attestations': [],
'recent_block_hashes': []
};

/*
Expand All @@ -46,17 +30,19 @@ class ActiveState {
}
}
}

if(toSet.hasOwnProperty('block_vote_cache')){
this.block_vote_cache = toSet['block_vote_cache']
} else {
this.block_vote_cache = {}
}
}

// Returns the number of recent attesters
const function numRecentAttesters() {
return this.recent_attesters.length;
const function numPendingAttestations() {
return this.pending_attestations.length;
}

// Returns the number of recent proposers
const function numRecentProposers() {
return this.recent_proposers.length;
}
}

exports.ActiveState = ActiveState;
42 changes: 42 additions & 0 deletions lodestar_chain/state/attestationRecord.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
var exports = module.exports = {};

class AttestationRecord {

var fields = {
// Slot number
'slot': 'int64',
// Shard ID
'shard_id': 'int16',
// List of block hashes that this signature is signing over that
// are NOT part of the current chain, in order of oldest to newest
'oblique_parent_hashes': ['hash32'],
// Block hash in the shard that we are attesting to
'shard_block_hash': 'hash32',
// Who is participating
'attester_bitfield': 'bytes',
// The actual signature
'aggregate_sig': ['int256']
}

var defaults = {
'slot': 0,
'shard_id': 0,
'oblique_parent_hashes': [],
'shard_block_hash': '\x00'.repeat(32);
'attester_bitfield': '',
'aggregate_sig': [0, 0],

}

contrusctor(var toSet) {
for(var key in fields) {
if(fields.hasOwnProperty(key)){
if(toSet.hasOwnProperty(key)) {
this.key = toSet.key;
} else {
this.key = defaults.key;
}
}
}
}
}
8 changes: 4 additions & 4 deletions lodestar_chain/state/crossLinkRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ var exports = module.exports = {};

class CrosslinkRecord {
var fields = {
// What epoch the crosslink was submitted in
'epoch':'int64',
// What dynasty the crosslink was submitted in
'dynasty':'int64',
// The block hash
'hash':'bytes32'
};

var defaults = {
'epoch':0,
'hash': 'x00'.repeat(32)
'dynasty':0,
'hash': '\x00'.repeat(32)
};

/*
Expand Down
76 changes: 34 additions & 42 deletions lodestar_chain/state/crystallizedState.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,52 @@ var exports = module.exports = {};

var CrosslinkRecord = require('./crossLinkRecord.js');
var ValidatorRecord = require('./validatorRecord.js');
var ShardAndCommittee = require('./shardAndCommittee.js');

class CrystallizedState {

var fields = {
// List of active validators
'active_validators': [ValidatorRecord],
// List of joined but not yet inducted validators
'queued_validators' : [ValidatorRecord],
// List of removed validators pending withdrawal
'exited_validators' : [ValidatorRecord],
// The permutation of validators used to determine who cross-links
// what shard in this epoch
'current_shuffling': ['int24'],
// The current epoch
'current_epoch' : 'int64',
// The last justified epoch
'last_justified_epoch': 'int64',
// The last finalized epoch
'last_finalized_epoch': 'int64',
// List of validators
'validators': [ValidatorRecord],
// Last CrystallizedState recalculation
'last_state_recalc': 'int64',
// What active validators are part of the attester set
// at what height, and in what shard. Starts at slot
// last_state_recalc - CYCLE_LENGTH
'indices_for_height': [[ShardAndCommittee]],
// The last justified slot
'last_justified_slot': 'int64',
// Number of consecutive justified slots ending at this one
'justified_streak': 'int16',
// The last finalized slot
'last_finalized_slot': 'int64',
// The current dynasty
'dynasty': 'int64',
'current_dynasty': 'int64',
// The next shard that assignment for cross-linking will start from
'next_shard': 'int16',
// The current FFG checkpoint
'current_checkpoint': 'bytes32',
'crosslinking_start_shard': 'int16',
// Records about the most recent crosslink for each shard
'crosslink_records': [CrosslinkRecord],
// Total balance of deposits
'total_deposits': 'int256'
'total_deposits': 'int256',
// Used to select the committees for each shard
'dynasty_seed': 'hash32',
// Last epoch the crosslink seed was reset
'dynasty_seed_last_reset': 'int64'
};

var defaults = {
'active_validators': [],
'queued_validators': [],
'exited_validators': [],
'current_shuffling': [],
'current_epoch': 0,
'last_justified_epoch': 0,
'last_finalized_epoch': 0,
'dynasty': 0,
'next_shard': 0,
'current_checkpoint': 'x00'.repeat(32),
'validators': [],
'last_state_recalc': 'int64',
'indices_for_height': [],
'last_justified_slot': 0,
'justified_streak': 0,
'last_finalized_slot': 0,
'current_dynasty': 0,
'crosslinking_start_shard': 0,
'crosslink_records': [],
'total_deposits': 0
'total_deposits': 0,
'dynasty_seed': '\x00'.repeat(32),
'dynasty_seed_last_reset': 0
};

/*
Expand All @@ -66,17 +68,7 @@ class CrystallizedState {

// Returns the number of active validators
const function numActivateValidators() {
return this.active_validators.length;
}

// Returns the number of queued validators
const function numQueuedValidators() {
return this.queued_validators.length;
}

// Returns the number of exited validators
const function numExitedValidators() {
return this.exited_validators.length;
return this.validators.length;
}

// Returns the number of crosslink records
Expand Down
30 changes: 30 additions & 0 deletions lodestar_chain/state/shardAndCommittee.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var exports = module.exports = {};

class ShardAndCommittee {

var fields = {
// The shard ID
'shard_id': 'int16',
// Validator indices
'committee': ['int24']
}

var defaults = {
'shard_id': 0,
'committee': []
}

contrusctor(var toSet) {
for(var key in fields) {
if(fields.hasOwnProperty(key)){
if(toSet.hasOwnProperty(key)) {
this.key = toSet.key;
} else {
this.key = defaults.key;
}
}
}
}
}

exports.ShardAndCommittee = ShardAndCommittee;
6 changes: 4 additions & 2 deletions lodestar_chain/state/validatorRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ class ValidatorRecord {
'randao_commitment': 'bytes32',
// Current balance
'balance': 'int64',
// Dynasty where the validator can (be inducted | be removed | withdraw)
'switch_dynasty': 'int64'
// Dynasty where the validator is inducted
'start_dynasty': 'int64',
// Dynasty where the validator leaves
'end_dynasty': 'int64'
};

var defaults = {};
Expand Down