Skip to content

Commit

Permalink
fix: pow issue (#214)
Browse files Browse the repository at this point in the history
* fix: revert changes

* fix: revert bacalhau id  & remove event parse code
  • Loading branch information
hunjixin authored Jun 30, 2024
1 parent ea63478 commit c9fb71a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
7 changes: 1 addition & 6 deletions pkg/executor/bacalhau/bacalhau.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,8 @@ func (executor *BacalhauExecutor) Id() (string, error) {
return "", fmt.Errorf("error calling get id results %s, %s", err.Error(), runOutputRaw)
}

splitOutputs := strings.Split(string(runOutputRaw), "\n")
splitOutputs := strings.Split(strings.Trim(string(runOutputRaw), " \t\n"), "\n")
runOutput := splitOutputs[len(splitOutputs)-1]
outputError := strings.Join(strings.Fields(strings.Join(splitOutputs[:len(splitOutputs)-1], " ")), " ")
if outputError != "" {
// TODO: we need to figure out if errors here are fatal or not
log.Warn().Msgf("error calling bacalhau id: %s", outputError)
}

var idResult struct {
ID string
Expand Down
8 changes: 4 additions & 4 deletions pkg/resourceprovider/resourceprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ func (resourceProvider *ResourceProvider) StartMineLoop(ctx context.Context) cha
})

submitWork := func(nonce *big.Int) {
txId, submission, err := resourceProvider.web3SDK.SubmitWork(ctx, nonce, nodeId)
txId, err := resourceProvider.web3SDK.SubmitWork(ctx, nonce, nodeId)
if err != nil {
log.Err(err).Msgf("Submit work fail")
return
}
log.Info().Str("address", submission.WalletAddress.String()).
Str("nodeid", submission.NodeId).
Str("Nonce", submission.Nonce.String()).
log.Info().Str("address", walletAddress.Hex()).
Str("nodeid", nodeId).
Str("Nonce", nonce.String()).
Str("txid", txId.String()).
Msgf("Mine and submit successfully")
}
Expand Down
15 changes: 5 additions & 10 deletions pkg/web3/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,27 +275,22 @@ func (sdk *Web3SDK) SubmitWork(
ctx context.Context,
nonce *big.Int,
nodeId string,
) (common.Hash, *pow.PowValidPOWSubmitted, error) {
) (common.Hash, error) {
tx, err := sdk.Contracts.Pow.SubmitWork(sdk.TransactOpts, nonce, nodeId)
if err != nil {
return common.Hash{}, nil, err
return common.Hash{}, err
}

receipt, err := sdk.WaitTx(ctx, tx)
if err != nil {
return common.Hash{}, nil, err
return common.Hash{}, err
}

if receipt.Status == 0 {
return tx.Hash(), nil, fmt.Errorf("excute transaction fail")
return tx.Hash(), fmt.Errorf("excute transaction fail")
}

validPosSubmission, err := sdk.Contracts.Pow.ParseValidPOWSubmitted(*receipt.Logs[0]) // todo need to check this result
if err != nil {
return common.Hash{}, nil, err
}

return tx.Hash(), validPosSubmission, nil
return tx.Hash(), nil
}

type PowValidPOWSubmission struct {
Expand Down

0 comments on commit c9fb71a

Please sign in to comment.