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

Runtime Policy instead of hardcoded constants #68

Merged
merged 14 commits into from
Mar 9, 2022
Merged

Conversation

vyzo
Copy link
Contributor

@vyzo vyzo commented Mar 9, 2022

This makes the miner policy runtime configurable instead of using hard coded constants, which allows us to write tests that can use different parameters and so on.

@vyzo vyzo mentioned this pull request Mar 9, 2022
@jennijuju jennijuju requested review from elmattic and raulk and removed request for elmattic March 9, 2022 17:18
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

This looks correct, but we should consider doing less. The number of deadlines per proving period, declarations, peer ID maximums, etc. don't really need to be configurable. The main things that need to be configurable are:

  • Most things involving epochs. Delays, etc.
  • Proof types.

I'm happy to go through the list with you if you want.

actors/runtime/src/runtime/policy.rs Show resolved Hide resolved
actors/runtime/src/runtime/policy.rs Outdated Show resolved Hide resolved
actors/miner/src/sector_map.rs Show resolved Hide resolved
actors/miner/src/lib.rs Show resolved Hide resolved
actors/miner/src/lib.rs Show resolved Hide resolved
@Stebalien
Copy link
Member

consider doing less

Specifically, so we can make this a bit less invasive. Although I'm not sure how much less invasive we'd end up making it.

Copy link
Contributor

@ZenGround0 ZenGround0 left a comment

Choose a reason for hiding this comment

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

Looks good

@@ -142,17 +142,19 @@ impl Actor {
.map(|address| resolve_control_address(rt, address))
.collect::<Result<_, _>>()?;

let policy = rt.policy();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Might as well do this above 133 so everyone can use the local variable to cut down on three function calls

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you would think!!!

thats what i had in the beginning, but then i met the borrow checker and he screamed at me...

));
}
{
let policy = rt.policy();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: move to directly precede the code block using it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same problem here.

actors/miner/src/lib.rs Outdated Show resolved Hide resolved
actors/runtime/src/runtime/policy.rs Show resolved Hide resolved
@arajasek
Copy link
Collaborator

arajasek commented Mar 9, 2022

Rebased on master

Comment on lines 1666 to 1669
Vec::with_capacity(rt.policy().wpost_period_deadlines as usize);
for _ in 0..rt.policy().wpost_period_deadlines {
decls_by_deadline.push(Vec::new());
}
Copy link
Member

Choose a reason for hiding this comment

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

The right way to write this is vec![Vec::new(); rt.policy().wpost_period_deadlines as usize];.

Copy link
Member

Choose a reason for hiding this comment

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

Well, that doesn't work because no clone... I could implement clone, but the version I pushed also works.

@Stebalien Stebalien enabled auto-merge (squash) March 9, 2022 19:01
@Stebalien Stebalien merged commit af49107 into master Mar 9, 2022
@Stebalien Stebalien deleted the feat/runtime-policy branch March 9, 2022 19:04
Comment on lines +150 to 155
.map_err(|e| {
e.downcast_default(
ExitCode::ErrSerialization,
"failed to assign proving period offset",
)
})?;
Copy link
Member

Choose a reason for hiding this comment

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

Is this correct indentation?

));
}
{
let policy = rt.policy();
Copy link
Member

Choose a reason for hiding this comment

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

nit: Move this to line 411.

Copy link
Member

@anorth anorth left a comment

Choose a reason for hiding this comment

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

I concur with @Stebalien that this extracted far too much. For next time, it would be better to make a change like this just with a few of the actually troublesome constants, thereby establishing a pattern that we can then move more into after it proves to solve our problems.

But also, the miner actor is not the only one with policy settings. The market and reward actor, to name a couple, have similar settings. So the naming here should be changed to MinerPolicy, or use a nested structure so that there's room for the others too.

use fvm_shared::clock::ChainEpoch;
use fvm_shared::clock::EPOCH_DURATION_SECONDS;

/// Maximum amount of sectors that can be aggregated.
Copy link
Member

Choose a reason for hiding this comment

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

These duplicated comments will rot. Please follow-up to delete them.

@Stebalien
Copy link
Member

So, it turns out that I lied. We can do this with feature flags as long as the policy lives in a separate crate. In this case, because it lives in the runtime crate, actors can simply enable these extra proof types at compile time with a build flag.

@vyzo
Copy link
Contributor Author

vyzo commented Mar 12, 2022

I concur with @Stebalien that this extracted far too much. For next time, it would be better to make a change like this just with a few of the actually troublesome constants, thereby establishing a pattern that we can then move more into after it proves to solve our problems.

I offered to reduce it, but @arajasek convinced @Stebalien that all this is fine.

But also, the miner actor is not the only one with policy settings. The market and reward actor, to name a couple, have similar settings. So the naming here should be changed to MinerPolicy, or use a nested structure so that there's room for the others too.

We should move the necessary constants in the policy for the other actors too, there is room to grow.

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

Successfully merging this pull request may close these issues.

None yet

6 participants