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
Startpost rpc #1312
Startpost rpc #1312
Conversation
activation/activation.go
Outdated
@@ -60,6 +61,12 @@ type BytesStore interface { | |||
Get(key []byte) ([]byte, error) | |||
} | |||
|
|||
const ( | |||
Idle = 1 |
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.
1 + iota ?
activation/activation.go
Outdated
@@ -222,6 +232,44 @@ func (b *Builder) buildNipstChallenge(epoch types.EpochId) error { | |||
return nil | |||
} | |||
|
|||
func (b *Builder) StartPost(rewardAddress address.Address, logicalDrive string, commitmentSize uint64) error { |
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.
logicalDrive
is a bit misleading, because it's not merely the drive. What about datadir
?
activation/activation.go
Outdated
@@ -222,6 +232,44 @@ func (b *Builder) buildNipstChallenge(epoch types.EpochId) error { | |||
return nil | |||
} | |||
|
|||
func (b *Builder) StartPost(rewardAddress address.Address, logicalDrive string, commitmentSize uint64) error { |
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.
Instead of commitmentSize
, perhaps space
, since it's already what's used.
@@ -436,6 +434,15 @@ func (app *SpacemeshApp) startServices() { | |||
log.Panic("cannot start block producer") | |||
} | |||
app.poetListener.Start() | |||
|
|||
if app.Config.StartMining { |
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.
Line 400:
if app.Config.CoinbaseAccount == "" {
app.log.Panic("cannot start mining without Coinbase account")
}
If StartMining
is false then you should not panic.
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.
This wasn't fixed yet.
And after what you did here:
if coinBase.Big().Uint64() == 0 && app.Config.StartMining {
app.log.Panic("invalid Coinbase account")
}
It should probably get removed entirely.
nipst/nipst.go
Outdated
@@ -28,6 +28,13 @@ type PostProverClient interface { | |||
// the amortized computational complexity can be made arbitrarily small. | |||
execute(id []byte, challenge []byte, timeout time.Duration) (proof *types.PostProof, err error) | |||
|
|||
// set the needed params for setting up post commitment in the specified logical drive and with | |||
// requested commitment size | |||
SetPostParams(logicalDrive string, commitmentSize uint64) |
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.
Method doc should start with SetPostParams
. Also, you can just call it SetParams
.
nipst/nipst.go
Outdated
// requested commitment size | ||
SetPostParams(logicalDrive string, commitmentSize uint64) | ||
|
||
//Reset deletes |
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.
Minor: space between "//" and "Reset". Dot in the end. More description.
nipst/nipst_test.go
Outdated
drive := "/tmp/anton" | ||
unitSize := 2048 | ||
_, err := nb.InitializePost(drive, uint64(unitSize)) | ||
defer nb.postProver.Reset() |
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.
You should also assert Reset
response.
nipst/nipst.go
Outdated
defTimeout := 5 * time.Second // TODO: replace temporary solution | ||
|
||
nb.postCfg.DataDir = logicalDrive | ||
nb.postCfg.SpacePerUnit = commitmentSize | ||
nb.postProver.SetPostParams(logicalDrive, commitmentSize) |
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.
Having post cfg on both the nipst builder and the post prover looks confusing. See if you can have in one place only.
@@ -222,6 +235,53 @@ func (b *Builder) buildNipstChallenge(epoch types.EpochId) error { | |||
return nil | |||
} | |||
|
|||
func (b *Builder) StartPost(rewardAddress address.Address, dataDir string, space uint64) error { |
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.
You changed logicalDrive
to dataDir
and commitmentSize
to space
here but not in many other places. It should all be the same, and if the context is lost, you can do postDatadir
& postSpace
, or something similar.
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.
There are many more leftovers.
activation/activation.go
Outdated
b.log.Info("Starting post, reward address: %x", rewardAddress) | ||
b.SetCoinbaseAccount(rewardAddress) | ||
b.postInitLock.Lock() | ||
if b.initStatus != Idle { |
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.
Last time I wrote:
It might be worth to check for
InProgress
status directly, instead of assuming that's the case if we're not onIdle
&&IsPostInitialized()
returns false. Whatever you think.
Now after IsPostInitialized()
removal, you're not covering the Done
case.
So this need to be fixed, and also you should set the Done
statue value if you're getting "already initialized" err from the initializer. Also, IMO "already initialized" should not be appended to "PoST initialization failed: " string.
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.
Why not to do this now as if b.initStatus == InProgress
?
} | ||
return &pb.SimpleMessage{Value: "ok"}, nil | ||
} | ||
|
||
func (s SpacemeshGrpcService) SetCommitmentSize(ctx context.Context, message *pb.CommitmentSizeMessage) (*pb.SimpleMessage, error) { |
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.
If you don't want to do it now, please leave a TODO.
@@ -167,6 +179,15 @@ func (s SpacemeshGrpcService) startServiceInternal(status chan bool) { | |||
|
|||
} | |||
|
|||
func (s SpacemeshGrpcService) StartMining(ctx context.Context, message *pb.InitPost) (*pb.SimpleMessage, error) { | |||
addr, err := address.StringToAddress(message.Coinbase) | |||
err = s.Mining.StartPost(addr, message.LogicalDrive, message.CommitmentSize) |
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.
If you don't want to do it now, please leave a TODO.
@@ -436,6 +434,15 @@ func (app *SpacemeshApp) startServices() { | |||
log.Panic("cannot start block producer") | |||
} | |||
app.poetListener.Start() | |||
|
|||
if app.Config.StartMining { |
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.
This wasn't fixed yet.
And after what you did here:
if coinBase.Big().Uint64() == 0 && app.Config.StartMining {
app.log.Panic("invalid Coinbase account")
}
It should probably get removed entirely.
activation/activation.go
Outdated
b.log.Info("Starting post, reward address: %x", rewardAddress) | ||
b.SetCoinbaseAccount(rewardAddress) | ||
b.postInitLock.Lock() | ||
if b.initStatus != Idle { |
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.
Why not to do this now as if b.initStatus == InProgress
?
@@ -222,6 +235,53 @@ func (b *Builder) buildNipstChallenge(epoch types.EpochId) error { | |||
return nil | |||
} | |||
|
|||
func (b *Builder) StartPost(rewardAddress address.Address, dataDir string, space uint64) error { |
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.
There are many more leftovers.
_, err := b.nipstBuilder.InitializePost(dataDir, space) // TODO: add proof to first ATX | ||
b.postInitLock.Lock() | ||
if err != nil { | ||
b.initStatus = Idle |
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.
You're not inspecting "already initialized" to set a Done
status.
If you don't want to do it now, leave a TODO.
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.
there is no "already initialized error, we use the initStatus
flag to know this
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.
I was referring to an error which comes from go-spacemesh/post
initializer. And my mistake - it will return "already completed" and not "already initialized" (that was the old version).
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.
then I think we should not return an error in such a case, and simply return the proof, I think It's not the best idea to keep track for specific error messages in between repos, since this can easily break
Closing #760.