-
Notifications
You must be signed in to change notification settings - Fork 170
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
updated ec spc and weight fn #538
Changes from all commits
a73b68e
49364df
06e880e
479f2a8
8f8ed70
a0c4ed1
0430204
04dbb6e
2533377
f23fa7d
e8b52bd
fde3386
743dcfd
e1c38ec
c8b3b06
c57ac59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package block_producer |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,9 @@ The Storage Power Consensus subsystem is the main interface which enables Fileco | |
Succinctly, the SPC subsystem offers the following services: | ||
- Access to the _Power Table_ for every subchain, accounting for individual storage miner power and total power on-chain. | ||
- Access to {{<sref expected_consensus>}} for individual storage miners, enabling: | ||
- Access to verifiable randomness {{<sref tickets>}}as needed in the rest of the protocol. | ||
- Access to verifiable randomness {{<sref tickets>}} as needed in the rest of the protocol. | ||
- Running {{<sref leader_election>}} to produce new blocks. | ||
- Running {{<sref chain_selection>}} across subchains using EC's weighting function. | ||
- Running {{<sref chain_selection>}} across subchains using EC's weighting function. | ||
- Identification of {{<sref finality "the most recently finalized tipset">}}, for use by all protocol participants. | ||
|
||
Much of the Storage Power Consensus' subsystem functionality is detailed in the code below but we touch upon some of its behaviors in more detail. | ||
|
@@ -22,34 +22,122 @@ Much of the Storage Power Consensus' subsystem functionality is detailed in the | |
|
||
## Distinguishing between storage miners and block miners | ||
|
||
There are two ways to earn Filecoin tokens in the Filecoin network: | ||
There are two ways to earn Filecoin tokens in the Filecoin network: | ||
- By participating in the {{<sref storage_market>}} as a storage provider and being paid by clients for file storage deals. | ||
- By mining new blocks on the network, helping modify system state and secure the Filecoin consensus mechanism. | ||
|
||
We must distinguish between both types of "miners" (storage and block miners). {{<sref leader_election>}} in Filecoin is predicated on a miner's storage power. Thus, while all block miners will be storage miners, the reverse is not necessarily true. | ||
|
||
However, given Filecoin's "useful Proof-of-Work" is achieved through file storage (PoRep and PoSt), there is little overhead cost for storage miners to participate in leader election. Such a {{<sref storage_miner_actor>}} need only register with the {{<sref storage_power_actor>}} in order to participate in Expected Consensus and mine blocks. | ||
|
||
{{<label power_table>}} | ||
## The Power Table | ||
## Repeated leader election attempts | ||
|
||
The portion of blocks a given miner generates through leader election in EC (and so the block rewards they earn) is proportional to their `Power Fraction` over time. That is, a miner whose storage represents 1% of total storage on the network should mine 1% of blocks on expectation. | ||
In the case that no miner is eligible to produce a block in a given round of EC, the storage power consensus subsystem will be called by the block producer to attempt another leader election by incrementing the nonce appended to the ticket drawn from the past in order to attempt to craft a new valid `ElectionProof` and trying again. | ||
|
||
SPC provides a power table abstraction which tracks miner power (i.e. miner storage in relation to network storage) over time. The power table is updated for new sector commitments (incrementing miner power), when PoSts fail to be put on-chain (decrementing miner power) or for other storage and consensus faults. | ||
{{<label ticket_chain>}} | ||
### The Ticket chain and randomness on-chain | ||
|
||
An invariant of the storage power consensus subsystem is that all storage in the power table must be verified. That is, miners can only derive power from storage they have already proven to the network. | ||
While each Filecoin block header contains a ticket field (see {{<sref tickets>}}), it is useful to provide nodes with a ticket chain abstraction. | ||
|
||
In order to achieve this, Filecoin delays updating power for new sector commitments until the first valid PoSt in the next proving period corresponding to that sector. | ||
Conversely, storage faults only lead to power loss once they are detected (up to one proving period after the fault) so miners will mine with no more power than they have used to store data over time. | ||
Namely, tickets are used throughout the Filecoin system as sources of on-chain randomness. For instance, | ||
- The {{<sref sector_sealer>}} uses tickets as SealSeeds to bind sector commitments to a given subchain. | ||
- The {{<sref post_generator>}} likewise uses tickets as PoStChallenges to prove sectors remain committed as of a given block. | ||
- They are drawn by the Storage Power subsystem as randomness in {{<leader_election>}} to determine their eligibility to mine a block | ||
- They are drawn by the Storage Power subsystem in order to generate new tickets for future use. | ||
|
||
Put another way, power accounting in the SPC is delayed between storage being proven or faulted, and power being updated in the power table (and so for leader election). This ensures fairness over time. | ||
Each of these ticket uses may require drawing tickets at different chain heights, according to the security requirements of the particular protocol making use of tickets. Due to the nature of Filecoin's Tipsets and the possibility of using losing tickets (that did not yield leaders in leader election) for randomness at a given height, tracking the canonical ticket of a subchain at a given height can be arduous to reason about in terms of blocks. To that end, it is helpful to create a ticket chain abstraction made up of only those tickets to be used for randomness at a given height. | ||
|
||
To illustrate this, an example: | ||
This ticket chain will track one-to-one with a block at each height in a given subchain, but omits certain details including other blocks mined at that height. | ||
|
||
Miner M1 has a provingPeriod of 30. M1 submits a PoST at height 39. Their next `provingPeriodEnd` will be 69, but M1 can submit a new PoST at any height X, for X in (39, 69]. Let's assume X is 67. | ||
It is composed inductively as follows. For a given chain: | ||
|
||
At height Y in (39, 67], M1 will attempt to generate an `ElectionProof` using the storage market actor from height 39 for their own power (and an actor from Y for total network power); at height 68, M1 will use the storage market actor from height 67 for their own power, and the storage market actor from height 68 for total power and so on. | ||
- At height 0, take the genesis block, return its ticket | ||
- At height n+1, take the heaviest tipset in our chain at height n. | ||
- select the block in that tipset with the smallest final ticket, return its ticket | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does "the heaviest tipset in our chain at height n" mean? either:
if (a), just remove the "take the heaviest tipset in our chain at height n", there's only one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
## Repeated leader election attempts | ||
Because a Tipset can contain multiple blocks, the smallest ticket in the Tipset must be drawn otherwise the block will be invalid. | ||
|
||
``` | ||
┌──────────────────────┐ | ||
│ │ | ||
│ │ | ||
│┌────┐ │ | ||
││ TA │ A │ | ||
└┴────┴────────────────┘ | ||
|
||
┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ | ||
│ | ||
│ | ||
┌────┐ │ TA < TB < TC | ||
││ TB │ B | ||
┴────┘─ ─ ─ ─ ─ ─ ─ ─ ┘ | ||
|
||
┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ | ||
│ | ||
│ | ||
┌────┐ │ | ||
││ TC │ C | ||
┴────┘─ ─ ─ ─ ─ ─ ─ ─ ┘ | ||
``` | ||
|
||
In the above diagram, a miner will use block A's Ticket to generate a new ticket (or an election proof farther in the future) since it is the smallest in the Tipset. | ||
|
||
## Drawing randomness for sector commitments | ||
|
||
Tickets are used as input to the SEAL above in order to tie Proofs-of-Replication to a given chain, thereby preventing long-range attacks (from another miner in the future trying to reuse SEALs). | ||
|
||
The ticket has to be drawn from a finalized block in order to prevent the miner from potential losing storage (in case of a chain reorg) even though their storage is intact. | ||
|
||
Verification should ensure that the ticket was drawn no farther back than necessary by the miner. We note that tickets can uniquely be associated to a given round in the protocol (lest a hash collision be found), but that the round number is explicited by the miner in `commitSector`. | ||
|
||
We present precisely how ticket selection and verification should work. In the below, we use the following notation: | ||
|
||
- `F`-- Finality (number of rounds) | ||
- `X`-- round in which SEALing starts | ||
- `Z`-- round in which the SEAL appears (in a block) | ||
- `Y`-- round announced in the SEAL `commitSector` (should be X, but a miner could use any Y <= X), denoted by the ticket selection | ||
- `T`-- estimated time for SEAL, dependent on sector size | ||
- `G = T + variance`-- necessary flexibility to account for network delay and SEAL-time variance. | ||
|
||
We expect Filecoin will be able to produce estimates for sector commitment time based on sector sizes, e.g.: | ||
`(estimate, variance) <--- SEALTime(sectors)` | ||
G and T will be selected using these. | ||
|
||
#### Picking a Ticket to Seal | ||
|
||
When starting to prepare a SEAL in round X, the miner should draw a ticket from X-F with which to compute the SEAL. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this here? shouldn't we just say tickets are how we produce randomness in the chain at a given epoch, and then let other things (ie seal) say how they use that randomness? |
||
|
||
#### Verifying a Seal's ticket | ||
|
||
When verifying a SEAL in round Z, a verifier should ensure that the ticket used to generate the SEAL is found in the range of rounds [Z-T-F-G, Z-T-F+G]. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be defined in Sealing, not here in SPC? unless you want it here because it's relevant to verifiable resource commitment? |
||
|
||
#### In Detail | ||
|
||
``` | ||
Prover | ||
─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ | ||
│ | ||
|
||
▼ | ||
X-F ◀───────F────────▶ X ◀──────────T─────────▶ Z | ||
-G . +G . . | ||
───(┌───────┐)───────────────( )──────────────────────( )────────▶ | ||
└───────┘ ' ' time | ||
[Z-T-F-G, Z-T-F+G] | ||
▲ | ||
|
||
└ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ | ||
Verifier | ||
``` | ||
|
||
Note that the prover here is submitting a message on chain (i.e. the SEAL). Using an older ticket than necessary to generate the SEAL is something the miner may do to gain more confidence about finality (since we are in a probabilistically final system). However it has a cost in terms of securing the chain in the face of long-range attacks (specifically, by mixing in chain randomness here, we ensure that an attacker going back a month in time to try and create their own chain would have to completely regenerate any and all sectors drawing randomness since to use for their fork's power). | ||
|
||
We break this down as follows: | ||
|
||
In the case that no miner is eligible to produce a block in a given round of EC, the storage power consensus subsystem will be called by the block producer to attempt another leader election. | ||
- The miner should draw from `X-F`. | ||
- The verifier wants to find what `X-F` should have been (to ensure the miner is not drawing from farther back) even though Y (i.e. the round of the ticket actually used) is an unverifiable value. | ||
- Thus, the verifier will need to make an inference about what `X-F` is likely to have been based on: | ||
- (known) round in which the message is received (Z) | ||
- (known) finality value (F) | ||
- (approximate) SEAL time (T) | ||
- Because T is an approximate value, and to account for network delay and variance in SEAL time across miners, the verifier allows for G offset from the assumed value of `X-F`: `Z-T-F`, hence verifying that the ticket is drawn from the range `[Z-T-F-G, Z-T-F+G]`. |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add note about clock synchrony? (ie why cant i just do all them at once until i win? because people wont accept your blocks early)