Skip to content

Commit

Permalink
Fix for peer timestamp handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 24, 2024
1 parent 6170155 commit 4ed00de
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Notable changes to Convex core modules will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.8.0] - 2024-12-20 - PROTONET
## [0.8.0] - 2024-12-24 - PROTONET

### Added

Expand All @@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `dissoc-in`, `update` and `update-in` core functions
- `switch` conditional macro
- Tagged values in Reader (e.g. `#Index {}`)
- `evict-peer` core function to remove old / understaked peers
- `evict-peer` core function to remove old / under-staked peers
- Automatic distribution of rewards to peers / delegated stakers
- Generalised CAD3 data support
- Logging for fungible token transfer events
Expand Down
4 changes: 1 addition & 3 deletions convex-core/src/main/java/convex/core/cvm/PeerStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,11 @@ protected ARecordGeneric withValues(AVector<ACell> newValues) {
return new PeerStatus(newValues);
}

public PeerStatus distributeBlockReward(State state, long peerFees) {
public PeerStatus distributeBlockReward(State state, long peerFees, long newTime) {
PeerStatus ps=addReward(peerFees);
long oldTime=ps.getTimestamp();

// Maybe bump timestamp
CVMLong timestamp=state.getTimestamp();
long newTime=timestamp.longValue();
if (oldTime<newTime) {
ps=ps.withTimestamp(newTime);
}
Expand Down
8 changes: 4 additions & 4 deletions convex-core/src/main/java/convex/core/cvm/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,18 +419,18 @@ private BlockResult applyTransactions(Block block, TransactionContext tctx) thro
//}
}

state=distributeFees(state,tctx.getPeer(),fees);
state=distributeFees(state,tctx.getPeer(),fees, block);

// TODO: any other things for complete block?
return BlockResult.create(state, results);
}

static State distributeFees(State state, AccountKey peer, long fees) {
static State distributeFees(State state, AccountKey peer, long fees, Block block) {
PeerStatus ps=state.getPeer(peer);
AccountStatus rewardPool=state.getAccount(Address.ZERO);
long poolBalance=rewardPool.getBalance();

long timeStamp=state.getTimestamp().longValue();
long timeStamp=block.getTimeStamp();
long timeReward=0;

if (ps==null) {
Expand All @@ -444,7 +444,7 @@ static State distributeFees(State state, AccountKey peer, long fees) {
long elapsed=Math.max(0, Math.min(timeStamp-oldTimestamp, CPoSConstants.MAX_REWARD_TIME));
timeReward=Math.max(0, Math.min(0, elapsed)); // TODO: update with reward calc

ps=ps.distributeBlockReward(state,peerFees+timeReward); // this also increases timestamp
ps=ps.distributeBlockReward(state,peerFees+timeReward,timeStamp); // this also increases timestamp

state=state.withPeer(peer, ps);

Expand Down

0 comments on commit 4ed00de

Please sign in to comment.