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

Implement Weight method + st/gt for heaviest ts #359

Merged
merged 12 commits into from
Apr 20, 2020
Merged

Conversation

dutterbutter
Copy link
Contributor

Summary of changes
Changes introduced in this pull request:

  • Implements the Weight method
  • Adds load_heaviest_tipset to be used when starting the node
  • Adds set_heaviest_tipset
  • Changes StoragePower to BigUint

Reference issue to close (if applicable)

Closes #118 #327

Other information and links

blockchain/blocks/src/tipset.rs Outdated Show resolved Hide resolved
blockchain/chain/src/store/chain_store.rs Show resolved Hide resolved
blockchain/chain/src/store/chain_store.rs Outdated Show resolved Hide resolved
blockchain/chain_sync/src/sync.rs Show resolved Hide resolved
Copy link
Contributor

@austinabell austinabell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm once this is resolved

Comment on lines 215 to 238
#[cfg(test)]
mod tests {
use super::*;
use address::Address;
use cid::multihash::Identity;

#[test]
fn genesis_test() {
let db = db::MemoryDB::default();

let cs = ChainStore::new(Arc::new(db));
let gen_block = BlockHeader::builder()
.epoch(1)
.weight((2 as u32).into())
.messages(Cid::new_from_cbor(&[], Identity))
.message_receipts(Cid::new_from_cbor(&[], Identity))
.state_root(Cid::new_from_cbor(&[], Identity))
.miner_address(Address::new_id(0).unwrap())
.build_and_validate()
.unwrap();

assert_eq!(cs.genesis().unwrap(), None);
cs.set_genesis(gen_block.clone()).unwrap();
assert_eq!(cs.genesis().unwrap(), Some(gen_block));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why exactly this test needs to be removed? Seems like at a high level that function should be able to be called without anything else, why can this not happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test needs more setup as it fails during the weight() method called from update_heaviest(). I could follow lotus more precisely and have a put_tipset() wrapper over persist_headers() where update_heaviest() would live and have set_genesis() only call persist_headers() since it only takes in a blockheader anyway. Otherwise, I will refactor the test to account for new required setup.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the setup that's missing though? that genesis block not existing in the blockstore? seems intuitive that this should not require other setup, but can look more into specifics later

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the setup that's missing is STORAGE_POWER_ACTOR_ADDR not being available in the weight method. I am adding a put_tipset method, similar to lotus; see here. As it seems we should not be calling update_heaviest() upon initializing the node with genesis.

blockchain/chain/src/store/chain_store.rs Outdated Show resolved Hide resolved
Comment on lines 215 to 238
#[cfg(test)]
mod tests {
use super::*;
use address::Address;
use cid::multihash::Identity;

#[test]
fn genesis_test() {
let db = db::MemoryDB::default();

let cs = ChainStore::new(Arc::new(db));
let gen_block = BlockHeader::builder()
.epoch(1)
.weight((2 as u32).into())
.messages(Cid::new_from_cbor(&[], Identity))
.message_receipts(Cid::new_from_cbor(&[], Identity))
.state_root(Cid::new_from_cbor(&[], Identity))
.miner_address(Address::new_id(0).unwrap())
.build_and_validate()
.unwrap();

assert_eq!(cs.genesis().unwrap(), None);
cs.set_genesis(gen_block.clone()).unwrap();
assert_eq!(cs.genesis().unwrap(), Some(gen_block));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the setup that's missing though? that genesis block not existing in the blockstore? seems intuitive that this should not require other setup, but can look more into specifics later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Chain Selection
3 participants