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.
|
||||
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.
|
||||
type Aggregator struct {
|
||||
@ -265,27 +265,6 @@ func (_Aggregator *AggregatorTransactorSession) RenounceOwnership() (*types.Tran
|
||||
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.
|
||||
//
|
||||
// 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/utils/ReentrancyGuard.sol";
|
||||
|
||||
interface IDioneStaking {
|
||||
function mine(address _minerAddr) external;
|
||||
function mineAndStake(address _minerAddr) external;
|
||||
function isLegitMiner(address _minerAddr) external returns (bool);
|
||||
}
|
||||
import "./DioneStaking.sol";
|
||||
|
||||
interface IMediator {
|
||||
function _receiveDataCallback(uint256 reqID, string memory data) external;
|
||||
}
|
||||
|
||||
contract Aggregator is Ownable, ReentrancyGuard {
|
||||
IDioneStaking public dioneStaking;
|
||||
DioneStaking public dioneStaking;
|
||||
|
||||
// Set DioneStaking contract. Can only be called by the owner.
|
||||
function setDioneStaking(IDioneStaking _dioneStaking) public onlyOwner {
|
||||
constructor(DioneStaking _dioneStaking) public {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -40,15 +40,18 @@ contract DioneStaking is Ownable, ReentrancyGuard {
|
||||
event Withdraw(address indexed miner, uint256 amount);
|
||||
event Mine(address indexed miner, uint256 blockNumber);
|
||||
|
||||
modifier onlyMiner(address _minerAddr) {
|
||||
require(isMiner(_minerAddr), "Exception: caller is not the miner");
|
||||
_;
|
||||
}
|
||||
|
||||
constructor(
|
||||
DioneToken _dione,
|
||||
address _aggregatorAddr,
|
||||
uint256 _minerReward,
|
||||
uint256 _startBlock,
|
||||
uint256 _minimumStake
|
||||
) public {
|
||||
dione = _dione;
|
||||
aggregatorAddr = _aggregatorAddr;
|
||||
minerReward = _minerReward;
|
||||
startBlock = _startBlock;
|
||||
minimumStake = _minimumStake;
|
||||
@ -107,8 +110,7 @@ contract DioneStaking is Ownable, ReentrancyGuard {
|
||||
}
|
||||
|
||||
function minerStake(address _minerAddr) external view returns (uint256) {
|
||||
MinerInfo storage miner = minerInfo[_minerAddr];
|
||||
return miner.amount;
|
||||
return minerInfo[_minerAddr].amount;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
function isLegitMiner(address _minerAddr) external returns (bool) {
|
||||
MinerInfo storage miner = minerInfo[_minerAddr];
|
||||
if (miner.amount >= minimumStake) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
function isMiner(address _minerAddr) public view returns (bool) {
|
||||
return minerInfo[_minerAddr].amount >= minimumStake;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
function setAggregator(address _aggregatorAddr) public onlyOwner {
|
||||
aggregatorAddr = _aggregatorAddr;
|
||||
}
|
||||
}
|
@ -25,10 +25,9 @@ func (n *Node) subscribeOnEthContracts(ctx context.Context) {
|
||||
if task == nil {
|
||||
continue
|
||||
}
|
||||
logrus.Info("BlockHash for Solana transaction: ", task.BlockHash)
|
||||
logrus.Info("Started new consensus round with ID: ", task.BlockHash)
|
||||
logrus.Info("Started new consensus round with ID: ", task.Signature)
|
||||
|
||||
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 {
|
||||
logrus.Errorf("Failed to propose task: %w", err)
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ func (e DrandRound) String() string {
|
||||
// DioneTask represents the values of task computation
|
||||
// Miner is an address of miner node
|
||||
type DioneTask struct {
|
||||
Miner peer.ID
|
||||
Type TaskType
|
||||
Ticket *Ticket
|
||||
ElectionProof *ElectionProof
|
||||
@ -49,6 +50,7 @@ func NewDioneTask(
|
||||
) *DioneTask {
|
||||
return &DioneTask{
|
||||
Type: t,
|
||||
Miner: miner,
|
||||
Ticket: ticket,
|
||||
ElectionProof: electionProof,
|
||||
BeaconEntries: beacon,
|
||||
|
Loading…
Reference in New Issue
Block a user