Vote & Reward Process
This section explains the node voting process.
The Vote and Reward Process
The core responsibility of a KTOC
node is to participate in the automated, decentralized process of selecting and rewarding a staker at the end of each reward epoch. This entire procedure, handled by the VoteAndReward
function in the node's code, is designed to be fair, transparent, and verifiable. It can be broken down into five distinct steps.
Step 1: Epoch Timing Check
Before taking any action, the node performs a simple timing check:
- It gets the current block number from its connected Ethereum endpoint.
- It queries the target
Ktv2
contract to read thestartBlock
of the current epoch and theepochInterval
duration. - The
endBlock
for the epoch is calculated (startBlock + epochInterval
). - The process only proceeds if the
currentBlock
is greater than theendBlock
. If it is not yet time to vote, the node simply waits and checks again later.
Step 2: Minimum Stake Calculation
This is the most critical step for ensuring fairness. The system does not simply look at staker balances at the end of the epoch. Instead, it calculates each user's minimum effective stake held throughout the entire epoch. This prevents users from staking a large amount just before the epoch ends to unfairly increase their chances.
- Event Filtering: The node scans the blockchain from the epoch's
startBlock
to itsendBlock
, collecting allStaked
andWithdrew
events emitted by theKtv2
contract. - Balance Reconstruction: It uses these events to reconstruct a historical timeline of each user's staked balance at every point during the epoch.
- Finding the Minimum: For each user who participated, the node identifies the lowest balance they held at any point between the
startBlock
andendBlock
. This value becomes their official, weighted stake amount for the reward calculation. - Total Minimum Stake: The node sums up the minimum stakes of all eligible users to get a
totalMin
value, which represents the total effective stake participating in the epoch's reward draw.
Step 3: Probabilistic Winner Selection
The winner is chosen via a weighted, on-chain lottery where the randomness is sourced directly from the blockchain itself, making it unpredictable and tamper-proof.
- Calculating Probabilities: Each user's probability of winning is a simple ratio:
User's Minimum Stake / Total Minimum Stake
. - Sourcing Randomness: The node waits for the next block to be mined immediately after the
endBlock
. It then fetches the hash of this future block. This block hash is an unknowable value at the time the epoch ends, making it a secure source of randomness. - The Drawing: The block hash is converted into a number between 0 and 1. The node then runs a lottery where each staker's probability range is stacked one after another. The user whose probability "slice" the random number falls into is declared the winner. If no one has staked, the winner defaults to the pre-defined burn address (
DEAD_ADDR
).
Step 4: Casting the On-Chain Vote
Once a winner is determined, the node makes its decision public and permanent.
- It creates and sends a transaction to the
Ktv2
contract, calling thevote()
function. - This transaction passes two arguments: the address of the selected winner and the block hash that was used for randomness.
- This action records the node's official vote in the contract's storage, visible to everyone on the blockchain.
Step 5: Achieving Consensus and Distributing the Reward
A single vote is not enough to release the funds. A predefined number of votes (consensusReq
) from different nodes is required.
- Checking Consensus: After its vote transaction is confirmed, the node immediately queries the
Ktv2
contract to see how many total votes the selected winner has accumulated for the current epoch. - Triggering the Payout: If the node's vote was the one that met or exceeded the
consensusReq
threshold, it immediately proceeds to call theRwd()
function on the contract. - The Reward: The
Rwd()
function sends the entire accumulated ETH balance of theKtv2
contract to the winner's address. The node that successfully triggers the reward also earns its operational fees as part of this process. If another node's vote reaches consensus and triggers the reward first, the process simply ends for all other nodes for the current epoch.