2020-10-28 17:35:56 +00:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
|
2020-11-12 14:18:30 +00:00
|
|
|
"github.com/libp2p/go-libp2p-core/peer"
|
|
|
|
|
2020-10-28 17:35:56 +00:00
|
|
|
"github.com/Secured-Finance/dione/config"
|
2020-11-12 14:18:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type TaskType byte
|
|
|
|
|
|
|
|
const (
|
|
|
|
EthereumTaskType = TaskType(iota)
|
|
|
|
FilecoinTaskType
|
|
|
|
SolanaTaskType
|
2020-10-28 17:35:56 +00:00
|
|
|
)
|
|
|
|
|
2020-11-14 00:03:47 +00:00
|
|
|
// DrandRound represents the round number in DRAND
|
|
|
|
type DrandRound int64
|
2020-10-28 17:35:56 +00:00
|
|
|
|
2020-11-14 00:03:47 +00:00
|
|
|
const TicketRandomnessLookback = DrandRound(1)
|
2020-10-31 03:48:15 +00:00
|
|
|
|
2020-11-14 00:03:47 +00:00
|
|
|
func (e DrandRound) String() string {
|
2020-10-28 17:35:56 +00:00
|
|
|
return strconv.FormatInt(int64(e), 10)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DioneTask represents the values of task computation
|
|
|
|
// Miner is an address of miner node
|
|
|
|
type DioneTask struct {
|
2020-11-12 14:18:30 +00:00
|
|
|
Type TaskType
|
|
|
|
Miner peer.ID
|
2020-10-28 17:35:56 +00:00
|
|
|
Ticket *Ticket
|
|
|
|
ElectionProof *ElectionProof
|
|
|
|
BeaconEntries []BeaconEntry
|
2020-11-12 14:18:30 +00:00
|
|
|
Signature *Signature
|
2020-11-14 00:03:47 +00:00
|
|
|
DrandRound DrandRound
|
2020-10-31 04:38:51 +00:00
|
|
|
Payload []byte
|
2020-11-15 05:59:46 +00:00
|
|
|
BlockHash string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDioneTask(
|
|
|
|
t TaskType,
|
|
|
|
miner peer.ID,
|
|
|
|
ticket *Ticket,
|
|
|
|
electionProof *ElectionProof,
|
|
|
|
beacon []BeaconEntry,
|
|
|
|
sig *Signature,
|
|
|
|
drand DrandRound,
|
|
|
|
payload []byte,
|
|
|
|
blockHash string,
|
|
|
|
) *DioneTask {
|
|
|
|
return &DioneTask{
|
|
|
|
Type: t,
|
|
|
|
Miner: miner,
|
|
|
|
Ticket: ticket,
|
|
|
|
ElectionProof: electionProof,
|
|
|
|
BeaconEntries: beacon,
|
|
|
|
Signature: sig,
|
|
|
|
DrandRound: drand,
|
|
|
|
Payload: payload,
|
|
|
|
BlockHash: blockHash,
|
|
|
|
}
|
2020-10-28 17:35:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var tasksPerEpoch = NewInt(config.TasksPerEpoch)
|
|
|
|
|
|
|
|
const sha256bits = 256
|