/
dispute_task.go
64 lines (54 loc) · 1.69 KB
/
dispute_task.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package dkgtasks
import (
"context"
"math/big"
"sync"
"github.com/MadBase/MadNet/blockchain"
"github.com/ethereum/go-ethereum/accounts"
"github.com/sirupsen/logrus"
)
// DisputeTask stores the data required to dispute shares
type DisputeTask struct {
sync.Mutex
eth blockchain.Ethereum
acct accounts.Account
logger *logrus.Logger
registrationEnd uint64
lastBlock uint64
publicKey [2]*big.Int
}
// NewDisputeTask creates a new task
func NewDisputeTask(logger *logrus.Logger, eth blockchain.Ethereum, acct accounts.Account, publicKey [2]*big.Int, registrationEnd uint64, lastBlock uint64) *DisputeTask {
return &DisputeTask{
logger: logger,
eth: eth,
acct: acct,
registrationEnd: registrationEnd,
lastBlock: lastBlock,
publicKey: blockchain.CloneBigInt2(publicKey),
}
}
// DoWork is the first attempt at distributing shares via ethdkg
func (t *DisputeTask) DoWork(ctx context.Context) bool {
t.logger.Info("DoWork() ...")
return t.doTask(ctx)
}
// DoRetry is subsequent attempts at distributing shares via ethdkg
func (t *DisputeTask) DoRetry(ctx context.Context) bool {
t.logger.Info("DoRetry() ...")
return t.doTask(ctx)
}
func (t *DisputeTask) doTask(ctx context.Context) bool {
return true
}
// ShouldRetry checks if it makes sense to try again
func (t *DisputeTask) ShouldRetry(ctx context.Context) bool {
// This wraps the retry logic for every phase, _except_ registration
return GeneralTaskShouldRetry(ctx, t.logger,
t.eth, t.acct, t.publicKey,
t.registrationEnd, t.lastBlock)
}
// DoDone creates a log entry saying task is complete
func (t *DisputeTask) DoDone() {
t.logger.Infof("done")
}