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

Make the PoW timeout configurable in config.yaml #57

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func main() {
rpcClient := rpc.NewRPCClient(conf.Server.NodeRpcUrl)

// Setup pow client
pow := pow.NewPippinPow(conf.Wallet.WorkPeers, utils.GetEnv("BPOW_KEY", ""), utils.GetEnv("BPOW_URL", ""))
pow := pow.NewPippinPow(conf.Wallet.WorkPeers, utils.GetEnv("BPOW_KEY", ""), utils.GetEnv("BPOW_URL", ""), conf.Wallet.WorkTimeout)

// Setup nano wallet instance with DB, options, etc.
nanoWallet := wallet.NanoWallet{
Expand Down
2 changes: 1 addition & 1 deletion apps/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func StartPippinServer() {
rpcClient := rpc.NewRPCClient(conf.Server.NodeRpcUrl)

// Setup pow client
pow := pow.NewPippinPow(conf.Wallet.WorkPeers, utils.GetEnv("BPOW_KEY", ""), utils.GetEnv("BPOW_URL", ""))
pow := pow.NewPippinPow(conf.Wallet.WorkPeers, utils.GetEnv("BPOW_KEY", ""), utils.GetEnv("BPOW_URL", ""), conf.Wallet.WorkTimeout)

// Setup nano wallet instance with DB, options, etc.
nanoWallet := wallet.NanoWallet{
Expand Down
1 change: 1 addition & 0 deletions libs/config/models/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type WalletConfig struct {
NodeWorkGenerate bool `yaml:"node_work_generate" default:"false"`
ReceiveMinimum string `yaml:"receive_minimum"`
AutoReceiveOnSend *bool `yaml:"auto_receive_on_send" default:"true"`
WorkTimeout int `yaml:"work_timeout" default:"30"`
}

type PippinConfig struct {
Expand Down
8 changes: 5 additions & 3 deletions libs/pow/pow.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type PippinPow struct {
workPeersFailing bool
bpowKey string
bpowUrl string
timeout time.Duration
mutex sync.Mutex
}

Expand All @@ -36,7 +37,7 @@ func (p *PippinPow) SetWorkPeersFailing(failing bool) {

// workPeers is an array of URLs to send work_generate requests to
// bpowKey and bpowUrl are optional, bpowUrl will default to boompow.banano.cc/graphql
func NewPippinPow(workPeers []string, bpowKey string, bpowUrl string) *PippinPow {
func NewPippinPow(workPeers []string, bpowKey string, bpowUrl string, workTimeout int) *PippinPow {
if bpowUrl == "" {
bpowUrl = "https://boompow.banano.cc/graphql"
}
Expand All @@ -46,6 +47,7 @@ func NewPippinPow(workPeers []string, bpowKey string, bpowUrl string) *PippinPow
workPeersFailing: false,
bpowUrl: bpowUrl,
bpowKey: bpowKey,
timeout: time.Duration(workTimeout) * time.Second,
}
}

Expand Down Expand Up @@ -165,7 +167,7 @@ func (p *PippinPow) WorkGenerateMeta(hash string, difficultyMultiplier int, vali
go WorkCancelAPIRequest(peer, hash)
}
return *result, nil
case <-time.After(30 * time.Second):
case <-time.After(p.timeout):
// Send work cancel
for _, peer := range p.WorkPeers {
go WorkCancelAPIRequest(peer, hash)
Expand All @@ -179,7 +181,7 @@ func (p *PippinPow) WorkGenerateMeta(hash string, difficultyMultiplier int, vali
return work, nil
}
}
return "", errors.New("Unable to generate work")
return "", errors.New("Unable to generate work - timed out")
}
}

Expand Down