fix: Proof-of-Stake mining reward on sending data to Aggregator contract
This commit is contained in:
parent
b5893b03f4
commit
cc034cc884
@ -27,7 +27,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AggregatorABI is the input ABI used to generate the binding from.
|
// AggregatorABI is the input ABI used to generate the binding from.
|
||||||
const AggregatorABI = "[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"dioneStaking\",\"outputs\":[{\"internalType\":\"contractIDioneStaking\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"contractIDioneStaking\",\"name\":\"_dioneStaking\",\"type\":\"address\"}],\"name\":\"setDioneStaking\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"reqID\",\"type\":\"uint256\"},{\"internalType\":\"string\",\"name\":\"data\",\"type\":\"string\"},{\"internalType\":\"contractIMediator\",\"name\":\"callbackAddress\",\"type\":\"address\"}],\"name\":\"collectData\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"
|
const AggregatorABI = "[{\"inputs\":[{\"internalType\":\"contractDioneStaking\",\"name\":\"_dioneStaking\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"dioneStaking\",\"outputs\":[{\"internalType\":\"contractDioneStaking\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"reqID\",\"type\":\"uint256\"},{\"internalType\":\"string\",\"name\":\"data\",\"type\":\"string\"},{\"internalType\":\"contractIMediator\",\"name\":\"callbackAddress\",\"type\":\"address\"}],\"name\":\"collectData\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"
|
||||||
|
|
||||||
// Aggregator is an auto generated Go binding around an Ethereum contract.
|
// Aggregator is an auto generated Go binding around an Ethereum contract.
|
||||||
type Aggregator struct {
|
type Aggregator struct {
|
||||||
@ -265,27 +265,6 @@ func (_Aggregator *AggregatorTransactorSession) RenounceOwnership() (*types.Tran
|
|||||||
return _Aggregator.Contract.RenounceOwnership(&_Aggregator.TransactOpts)
|
return _Aggregator.Contract.RenounceOwnership(&_Aggregator.TransactOpts)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDioneStaking is a paid mutator transaction binding the contract method 0xc2cf98a4.
|
|
||||||
//
|
|
||||||
// Solidity: function setDioneStaking(address _dioneStaking) returns()
|
|
||||||
func (_Aggregator *AggregatorTransactor) SetDioneStaking(opts *bind.TransactOpts, _dioneStaking common.Address) (*types.Transaction, error) {
|
|
||||||
return _Aggregator.contract.Transact(opts, "setDioneStaking", _dioneStaking)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetDioneStaking is a paid mutator transaction binding the contract method 0xc2cf98a4.
|
|
||||||
//
|
|
||||||
// Solidity: function setDioneStaking(address _dioneStaking) returns()
|
|
||||||
func (_Aggregator *AggregatorSession) SetDioneStaking(_dioneStaking common.Address) (*types.Transaction, error) {
|
|
||||||
return _Aggregator.Contract.SetDioneStaking(&_Aggregator.TransactOpts, _dioneStaking)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetDioneStaking is a paid mutator transaction binding the contract method 0xc2cf98a4.
|
|
||||||
//
|
|
||||||
// Solidity: function setDioneStaking(address _dioneStaking) returns()
|
|
||||||
func (_Aggregator *AggregatorTransactorSession) SetDioneStaking(_dioneStaking common.Address) (*types.Transaction, error) {
|
|
||||||
return _Aggregator.Contract.SetDioneStaking(&_Aggregator.TransactOpts, _dioneStaking)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TransferOwnership is a paid mutator transaction binding the contract method 0xf2fde38b.
|
// TransferOwnership is a paid mutator transaction binding the contract method 0xf2fde38b.
|
||||||
//
|
//
|
||||||
// Solidity: function transferOwnership(address newOwner) returns()
|
// Solidity: function transferOwnership(address newOwner) returns()
|
||||||
|
File diff suppressed because one or more lines are too long
@ -3,26 +3,21 @@ pragma solidity >= 0.5.0 < 0.7.0;
|
|||||||
|
|
||||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||||
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
|
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
|
||||||
|
import "./DioneStaking.sol";
|
||||||
interface IDioneStaking {
|
|
||||||
function mine(address _minerAddr) external;
|
|
||||||
function mineAndStake(address _minerAddr) external;
|
|
||||||
function isLegitMiner(address _minerAddr) external returns (bool);
|
|
||||||
}
|
|
||||||
|
|
||||||
interface IMediator {
|
interface IMediator {
|
||||||
function _receiveDataCallback(uint256 reqID, string memory data) external;
|
function _receiveDataCallback(uint256 reqID, string memory data) external;
|
||||||
}
|
}
|
||||||
|
|
||||||
contract Aggregator is Ownable, ReentrancyGuard {
|
contract Aggregator is Ownable, ReentrancyGuard {
|
||||||
IDioneStaking public dioneStaking;
|
DioneStaking public dioneStaking;
|
||||||
|
|
||||||
// Set DioneStaking contract. Can only be called by the owner.
|
constructor(DioneStaking _dioneStaking) public {
|
||||||
function setDioneStaking(IDioneStaking _dioneStaking) public onlyOwner {
|
|
||||||
dioneStaking = _dioneStaking;
|
dioneStaking = _dioneStaking;
|
||||||
}
|
}
|
||||||
|
|
||||||
function collectData(uint256 reqID, string memory data, IMediator callbackAddress) public nonReentrant {
|
function collectData(uint256 reqID, string memory data, IMediator callbackAddress) public {
|
||||||
|
dioneStaking.mine(msg.sender);
|
||||||
callbackAddress._receiveDataCallback(reqID, data);
|
callbackAddress._receiveDataCallback(reqID, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,15 +40,18 @@ contract DioneStaking is Ownable, ReentrancyGuard {
|
|||||||
event Withdraw(address indexed miner, uint256 amount);
|
event Withdraw(address indexed miner, uint256 amount);
|
||||||
event Mine(address indexed miner, uint256 blockNumber);
|
event Mine(address indexed miner, uint256 blockNumber);
|
||||||
|
|
||||||
|
modifier onlyMiner(address _minerAddr) {
|
||||||
|
require(isMiner(_minerAddr), "Exception: caller is not the miner");
|
||||||
|
_;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
DioneToken _dione,
|
DioneToken _dione,
|
||||||
address _aggregatorAddr,
|
|
||||||
uint256 _minerReward,
|
uint256 _minerReward,
|
||||||
uint256 _startBlock,
|
uint256 _startBlock,
|
||||||
uint256 _minimumStake
|
uint256 _minimumStake
|
||||||
) public {
|
) public {
|
||||||
dione = _dione;
|
dione = _dione;
|
||||||
aggregatorAddr = _aggregatorAddr;
|
|
||||||
minerReward = _minerReward;
|
minerReward = _minerReward;
|
||||||
startBlock = _startBlock;
|
startBlock = _startBlock;
|
||||||
minimumStake = _minimumStake;
|
minimumStake = _minimumStake;
|
||||||
@ -107,8 +110,7 @@ contract DioneStaking is Ownable, ReentrancyGuard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function minerStake(address _minerAddr) external view returns (uint256) {
|
function minerStake(address _minerAddr) external view returns (uint256) {
|
||||||
MinerInfo storage miner = minerInfo[_minerAddr];
|
return minerInfo[_minerAddr].amount;
|
||||||
return miner.amount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update miner reward in DIONE tokens, only can be executed by owner of the contract
|
// Update miner reward in DIONE tokens, only can be executed by owner of the contract
|
||||||
@ -117,12 +119,8 @@ contract DioneStaking is Ownable, ReentrancyGuard {
|
|||||||
minerReward = _minerReward;
|
minerReward = _minerReward;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isLegitMiner(address _minerAddr) external returns (bool) {
|
function isMiner(address _minerAddr) public view returns (bool) {
|
||||||
MinerInfo storage miner = minerInfo[_minerAddr];
|
return minerInfo[_minerAddr].amount >= minimumStake;
|
||||||
if (miner.amount >= minimumStake) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update minimum stake in DIONE tokens for miners, only can be executed by owner of the contract
|
// Update minimum stake in DIONE tokens for miners, only can be executed by owner of the contract
|
||||||
@ -131,4 +129,7 @@ contract DioneStaking is Ownable, ReentrancyGuard {
|
|||||||
minimumStake = _minimumStake;
|
minimumStake = _minimumStake;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setAggregator(address _aggregatorAddr) public onlyOwner {
|
||||||
|
aggregatorAddr = _aggregatorAddr;
|
||||||
|
}
|
||||||
}
|
}
|
@ -25,10 +25,9 @@ func (n *Node) subscribeOnEthContracts(ctx context.Context) {
|
|||||||
if task == nil {
|
if task == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
logrus.Info("BlockHash for Solana transaction: ", task.BlockHash)
|
logrus.Info("Started new consensus round with ID: ", task.Signature)
|
||||||
logrus.Info("Started new consensus round with ID: ", task.BlockHash)
|
|
||||||
|
|
||||||
err = n.ConsensusManager.Propose(event.RequestID.String(), task.BlockHash, event.RequestID, event.CallbackAddress)
|
err = n.ConsensusManager.Propose(event.RequestID.String(), string(task.Payload), event.RequestID, event.CallbackAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("Failed to propose task: %w", err)
|
logrus.Errorf("Failed to propose task: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ func (e DrandRound) String() string {
|
|||||||
// DioneTask represents the values of task computation
|
// DioneTask represents the values of task computation
|
||||||
// Miner is an address of miner node
|
// Miner is an address of miner node
|
||||||
type DioneTask struct {
|
type DioneTask struct {
|
||||||
|
Miner peer.ID
|
||||||
Type TaskType
|
Type TaskType
|
||||||
Ticket *Ticket
|
Ticket *Ticket
|
||||||
ElectionProof *ElectionProof
|
ElectionProof *ElectionProof
|
||||||
@ -49,6 +50,7 @@ func NewDioneTask(
|
|||||||
) *DioneTask {
|
) *DioneTask {
|
||||||
return &DioneTask{
|
return &DioneTask{
|
||||||
Type: t,
|
Type: t,
|
||||||
|
Miner: miner,
|
||||||
Ticket: ticket,
|
Ticket: ticket,
|
||||||
ElectionProof: electionProof,
|
ElectionProof: electionProof,
|
||||||
BeaconEntries: beacon,
|
BeaconEntries: beacon,
|
||||||
|
Loading…
Reference in New Issue
Block a user