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

Implementing phase 1 spec - add_header #83

Merged
merged 9 commits into from
May 7, 2018

Conversation

NIC619
Copy link
Collaborator

@NIC619 NIC619 commented May 1, 2018

What was wrong?

implement part of SMC modification - stage 1 #76

How was it fixed?

Implement add_header and submit_vote functions.

  1. add_header:
  • Everyone can call add_header to submit collation header(i.e. collation_records).
  • For each shard and in each period only one collation record can be submitted. Use records_updated_period to keep track of in which period was the latest collation record submitted.
  • current_vote which keeps track of the vote count is cleared once a new collation record is submitted.
  • tests

Cute Animal Picture

put a cute animal picture link inside the parentheses

@NIC619 NIC619 requested review from mhchia and hwwhww May 1, 2018 14:45
@NIC619 NIC619 force-pushed the implementing_phase_1_spec branch from b1883df to 2b6b676 Compare May 1, 2018 14:52
@NIC619 NIC619 force-pushed the implementing_phase_1_spec branch from 2b6b676 to 106da53 Compare May 1, 2018 14:57
)
return collation_score
def get_collation_chunk_root(period: int128, shard_id: int128) -> bytes32:
return self.collation_records[period][shard_id].chunk_root
Copy link
Collaborator

@mhchia mhchia May 1, 2018

Choose a reason for hiding this comment

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

Why not we just set the collation_records to public, and use its getter to access this state variable? Or does it not work well?

assert self.receipts[receipt_id].sender == msg.sender
self.receipts[receipt_id].tx_gasprice = tx_gasprice
return True
return True
Copy link
Collaborator

Choose a reason for hiding this comment

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

No newline at end of file?

chunk_root,
private_key=None,
gas=None,
gas_price=None,):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems a redundant comma

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it intentional?

self.shard_head[shard_id] = entire_header_hash
is_new_head = True
# Update records_updated_period
self.records_updated_period[shard_id] = current_period

Choose a reason for hiding this comment

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

since it's a new header, do we want to clear current_vote[shard_id]'s last byte to 0 here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes we do! I plan to do this along with submit_vote because then others can get a more clear picture about how current_vote is used when they look into the commit history.

Choose a reason for hiding this comment

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

Got it. Thanks! I'm doing the same implementation in solidity. Feel free to take a look and leave me any feedback : )
prysmaticlabs/prysm#97

Copy link
Collaborator

@hwwhww hwwhww left a comment

Choose a reason for hiding this comment

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

Maybe add some tests for add_header for the assertions:

  1. The successful case.
  2. The second proposer tries to send the add-header-tx in the same period of the same shards.
  3. The proposer tries to send the add-header-tx in the wrong period.

collation_number,
is_new_head,
_score,
chunk_root,
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we have self.collation_records[period][shard_id], we don't need addHeader/CollationAdded log now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

After a second thought, a log can save client some effort as they don't have to keep polling the contract.

@NIC619
Copy link
Collaborator Author

NIC619 commented May 2, 2018

Decided to move submit_vote part to next PR for ease of review.

@NIC619 NIC619 changed the title [WIP]Implementing phase 1 spec - add_header and submit_vote Implementing phase 1 spec - add_header and submit_vote May 2, 2018
@NIC619 NIC619 changed the title Implementing phase 1 spec - add_header and submit_vote Implementing phase 1 spec - add_header May 2, 2018
# Attempts to process a collation header, returns True on success, reverts on failure.
@public
def add_header(
period: int128,
Copy link
Collaborator

Choose a reason for hiding this comment

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

One sudden thought, is it feasible that we remove period from the parameters of add_header?
Since period can only be floor(block.number / self.PERIOD_LENGTH) if add_header success.

Copy link
Collaborator Author

@NIC619 NIC619 May 5, 2018

Choose a reason for hiding this comment

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

If period was not specified, it is possible that headers intended for different period get included.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, though the nonce in the transaction might prevent it from being included again, IMO the gas saving is probably not worth it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agree. It is more clear that pass it as parameter.

chunk_root,
private_key=None,
gas=None,
gas_price=None,):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it intentional?

# Check that collation record of shard 0 remains the same and transaction consume all gas
assert smc_handler.records_updated_period(0) == 1
assert smc_handler.get_collation_chunk_root(1, 0) == CHUNK_ROOT_1_0
assert web3.eth.getTransactionReceipt(tx_hash)['gasUsed'] == default_gas
Copy link
Collaborator

@hwwhww hwwhww May 5, 2018

Choose a reason for hiding this comment

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

Sorry, second thought: HeaderAdded log that returns True/False may be helpful for the client side to determine whether the add_header tx is included.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Log will be emitted only if transaction succeed, i.e. passing all the checks. If client catches a HeaderAdded log, he can be sure that header is added.

Copy link
Collaborator Author

@NIC619 NIC619 May 6, 2018

Choose a reason for hiding this comment

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

Currently I name it AddHeader to conform with log naming pattern, e.g, RegisterNotary, DeregisterNotary.
We can change them to HeaderAdded, NotaryRegistered in the future if we like.

@NIC619 NIC619 merged commit 1019ae3 into ethereum:develop May 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants