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

Startpost rpc #1312

Merged
merged 16 commits into from Aug 15, 2019
Merged

Startpost rpc #1312

merged 16 commits into from Aug 15, 2019

Conversation

antonlerner
Copy link
Contributor

@antonlerner antonlerner commented Aug 12, 2019

Closing #760.

@@ -60,6 +61,12 @@ type BytesStore interface {
Get(key []byte) ([]byte, error)
}

const (
Idle = 1
Copy link
Contributor

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 Show resolved Hide resolved
activation/activation.go Show resolved Hide resolved
@@ -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 {
Copy link
Contributor

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?

@@ -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 {
Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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.

drive := "/tmp/anton"
unitSize := 2048
_, err := nb.InitializePost(drive, uint64(unitSize))
defer nb.postProver.Reset()
Copy link
Contributor

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)
Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Contributor

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 Show resolved Hide resolved
b.log.Info("Starting post, reward address: %x", rewardAddress)
b.SetCoinbaseAccount(rewardAddress)
b.postInitLock.Lock()
if b.initStatus != Idle {
Copy link
Contributor

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 on Idle && 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.

Copy link
Contributor

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) {
Copy link
Contributor

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)
Copy link
Contributor

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 {
Copy link
Contributor

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.

b.log.Info("Starting post, reward address: %x", rewardAddress)
b.SetCoinbaseAccount(rewardAddress)
b.postInitLock.Lock()
if b.initStatus != Idle {
Copy link
Contributor

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 {
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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).

Copy link
Contributor Author

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

@antonlerner antonlerner merged commit 547510f into develop Aug 15, 2019
@moshababo moshababo mentioned this pull request Aug 20, 2019
@noamnelke noamnelke deleted the startpost_rpc branch December 25, 2019 19:20
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.

None yet

3 participants