Skip to content

Commit

Permalink
add --no-hot-stop param
Browse files Browse the repository at this point in the history
  • Loading branch information
tranvictor committed Mar 20, 2017
1 parent e848534 commit f2a0120
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
11 changes: 10 additions & 1 deletion cmd/kovan/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ func Initialize(c *cli.Context) *smartpool.Input {
contractAddr := c.String("spcontract")
// minerAddr := "0x001aDBc838eDe392B5B054A47f8B8c28f2fA9F3F"
minerAddr := c.String("miner")
hotStop := !c.Bool("no-hot-stop")
if hotStop {
fmt.Printf("SmartPool is in Hot-Stop mode: It will exit immediately if the contract returns errors.\n")
}
extraData := ""
return smartpool.NewInput(
rpcEndPoint, keystorePath, shareThreshold, shareDifficulty,
submitInterval, contractAddr, minerAddr, extraData,
submitInterval, contractAddr, minerAddr, extraData, hotStop,
)
}

Expand Down Expand Up @@ -144,6 +148,7 @@ func Run(c *cli.Context) error {
ethereumClaimRepo, ethereumContract,
common.HexToAddress(input.MinerAddress()),
input.SubmitInterval(), input.ShareThreshold(),
input.HotStop(),
)
server := ethminer.NewRPCServer(
smartpool.Output,
Expand Down Expand Up @@ -187,6 +192,10 @@ func BuildAppCommandLine() *cli.App {
Name: "miner",
Usage: "The address that would be paid by SmartPool. This is often your address. (Default: First account in your keystore.)",
},
cli.BoolFlag{
Name: "no-hot-stop",
Usage: "If hot-stop is true, SmartPool will stop running once it got an error returned from the Contract",
},
}
app.Action = Run
return app
Expand Down
2 changes: 1 addition & 1 deletion ethereum/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (c *Contract) Register(paymentAddress common.Address) error {
}

func (c *Contract) SubmitClaim(claim smartpool.Claim) error {
fmt.Printf("Mix: 0x%s - Max: 0x%s - Diff: 0x%s\n", claim.Min().Text(16), claim.Max().Text(16), claim.Difficulty().Text(16))
fmt.Printf("Min: 0x%s - Max: 0x%s - Diff: 0x%s\n", claim.Min().Text(16), claim.Max().Text(16), claim.Difficulty().Text(16))
return c.client.SubmitClaim(
claim.NumShares(), claim.Difficulty(),
claim.Min(), claim.Max(), claim.AugMerkle().Big())
Expand Down
5 changes: 4 additions & 1 deletion input.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Input struct {
contractAddr string
minerAddr string
extraData string
hotStop bool
}

func (i *Input) RPCEndpoint() string { return i.rpcEndPoint }
Expand All @@ -25,6 +26,7 @@ func (i *Input) SubmitInterval() time.Duration { return i.submitInterval }
func (i *Input) ContractAddress() string { return i.contractAddr }
func (i *Input) MinerAddress() string { return i.minerAddr }
func (i *Input) ExtraData() string { return i.extraData }
func (i *Input) HotStop() bool { return i.hotStop }
func (i *Input) SetMinerAddress(addr common.Address) {
i.minerAddr = addr.Hex()
}
Expand All @@ -41,9 +43,10 @@ func NewInput(
contractAddr string,
minerAddr string,
extraData string,
hotStop bool,
) *Input {
return &Input{
rpcEndPoint, keystorePath, shareThreshold, shareDifficulty,
submitInterval, contractAddr, minerAddr, extraData,
submitInterval, contractAddr, minerAddr, extraData, hotStop,
}
}
1 change: 1 addition & 0 deletions interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type UserInput interface {
ContractAddress() string
MinerAddress() string
ExtraData() string
HotStop() bool
}

// Global output mechanism
Expand Down
22 changes: 16 additions & 6 deletions protocol/smartpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/SmartPool/smartpool-client"
"github.com/ethereum/go-ethereum/common"
"math/big"
"os"
"time"
)

Expand All @@ -31,6 +32,7 @@ type SmartPool struct {
MinerAddress common.Address
SubmitInterval time.Duration
ShareThreshold int
HotStop bool
loopStarted bool
ticker <-chan time.Time
}
Expand Down Expand Up @@ -79,6 +81,7 @@ func (sp *SmartPool) AcceptSolution(s smartpool.Solution) bool {
smartpool.Output.Printf("Share's counter (0x%s) is lower than last claim max counter (0x%s)\n", share.Counter().Text(16), sp.LatestCounter.Text(16))
}
if share == nil || share.Counter().Cmp(sp.LatestCounter) <= 0 {
smartpool.Output.Printf("Share is discarded.\n")
return false
}
sp.ClaimRepo.AddShare(share)
Expand Down Expand Up @@ -113,15 +116,15 @@ func (sp *SmartPool) Submit() bool {
return false
}
smartpool.Output.Printf("The claim is successfully submitted.\n")
smartpool.Output.Printf("Waiting for verification index.\n")
smartpool.Output.Printf("Waiting for verification index...")
index := sp.GetVerificationIndex(claim)
smartpool.Output.Printf("Verification index of %d has been requested. Submitting verification for the claim.\n", index.Int64())
smartpool.Output.Printf("Verification index of %d has been requested. Submitting claim verification.\n", index.Int64())
verErr := sp.Contract.VerifyClaim(index, claim)
if verErr != nil {
smartpool.Output.Printf("Got error verifing claim: %s\n", verErr)
smartpool.Output.Printf("%s\n", verErr)
return false
}
smartpool.Output.Printf("Verified the claim.\n")
smartpool.Output.Printf("Claim is successfully verified.\n")
smartpool.Output.Printf("Set Latest Counter to %s.\n", claim.Max())
return true
}
Expand All @@ -132,9 +135,15 @@ func (sp *SmartPool) actOnTick() {
smartpool.Output.Printf("Recovered in actOnTick: %v\n", r)
}
}()
var ok bool
for _ = range sp.ticker {
sp.Submit()
ok = sp.Submit()
if !ok && sp.HotStop {
smartpool.Output.Printf("SmartPool stopped. If you want SmartPool to keep running, please use \"--hot-stop false\".\n")
break
}
}
os.Exit(1)
}

// Run can be called at most once to start a loop to submit and verify claims
Expand All @@ -161,7 +170,7 @@ func (sp *SmartPool) Run() bool {
func NewSmartPool(
sr smartpool.ShareReceiver, nc smartpool.NetworkClient,
cr ClaimRepo, co smartpool.Contract, ma common.Address,
interval time.Duration, threshold int) *SmartPool {
interval time.Duration, threshold int, hotStop bool) *SmartPool {
return &SmartPool{
ShareReceiver: sr,
NetworkClient: nc,
Expand All @@ -170,6 +179,7 @@ func NewSmartPool(
MinerAddress: ma,
SubmitInterval: interval,
ShareThreshold: threshold,
HotStop: hotStop,
loopStarted: false,
// TODO: should be persist between startups instead of having 0 hardcoded
LatestCounter: big.NewInt(0),
Expand Down

1 comment on commit f2a0120

@tranvictor
Copy link
Member Author

Choose a reason for hiding this comment

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

resolve #3

Please sign in to comment.