Skip to content

Commit

Permalink
Remove unnecessary back and forth transfers in IexecPoco2Delegate (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyjams authored Dec 18, 2024
2 parents d443cc4 + 0ac30f0 commit 5ef8455
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog

## vNEXT

### Updated contracts
- [x] `IexecPoco2Delegate.sol`

### Features
- Remove unnecessary back and forth transfers in `IexecPoco2Delegate` happening during `claim(..)`. (#167)
- Remove references to blockscout v5. (#161)
- Migrate integration test files to Typescript & Hardhat:
- 000_fullchain.js (#156, #157)
Expand Down
11 changes: 9 additions & 2 deletions contracts/modules/delegates/IexecPoco2Delegate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,15 @@ contract IexecPoco2Delegate is IexecPoco2, DelegateBase, IexecEscrow, SignatureV

unlock(deal.sponsor, taskPrice); // Refund the payer of the task
seize(deal.workerpool.owner, poolstake, _taskid);
reward(KITTY_ADDRESS, poolstake, _taskid); // → Kitty / Burn
lock(KITTY_ADDRESS, poolstake); // → Kitty / Burn
/**
* Reward kitty and lock value on it.
* Next lines optimize simple `reward(kitty, ..)` and `lock(kitty, ..)` calls
* where functions would together uselessly transfer value from main PoCo
* proxy to kitty, then would transfer value back from kitty to main PoCo proxy.
*/
m_frozens[KITTY_ADDRESS] += poolstake; // → Kitty / Burn
emit Reward(KITTY_ADDRESS, poolstake, _taskid);
emit Lock(KITTY_ADDRESS, poolstake);
}

/***************************************************************************
Expand Down
30 changes: 13 additions & 17 deletions test/byContract/IexecPoco/04_finalize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ describe('IexecPoco2#finalize', async () => {
const sponsorFrozenBefore = await iexecPoco.frozenOf(sponsor.address);

await expect(iexecPocoAsScheduler.finalize(taskId, results, '0x'))
.to.emit(iexecPoco, 'TaskFinalize')
.to.changeTokenBalances(
iexecPoco,
[requester, sponsor, appProvider, datasetProvider],
Expand All @@ -348,7 +347,8 @@ describe('IexecPoco2#finalize', async () => {
appPrice, // app provider is rewarded
0, // but dataset provider is not rewarded
],
);
)
.to.emit(iexecPoco, 'TaskFinalize');
expect(await iexecPoco.frozenOf(requester.address)).to.be.equal(
requesterFrozenBefore - taskPrice,
);
Expand Down Expand Up @@ -517,22 +517,18 @@ describe('IexecPoco2#finalize', async () => {
(await iexecPoco.viewTask(kittyFillingDeal.taskId)).finalDeadline,
);
await expect(iexecPoco.claim(kittyFillingDeal.taskId))
.to.emit(iexecPoco, 'Transfer')
.withArgs(iexecPoco.address, kittyAddress, kittyFillingSchedulerTaskStake)
.to.emit(iexecPoco, 'Reward')
.withArgs(kittyAddress, kittyFillingSchedulerTaskStake, kittyFillingDeal.taskId)
.to.emit(iexecPoco, 'Transfer')
.withArgs(kittyAddress, iexecPoco.address, kittyFillingSchedulerTaskStake)
.to.emit(iexecPoco, 'Lock')
.withArgs(kittyAddress, kittyFillingSchedulerTaskStake)
.to.changeTokenBalances(
iexecPoco,
[iexecPoco, kittyAddress],
[
-workerpoolPriceToFillKitty, // deal payer is refunded
0,
],
);
)
.to.emit(iexecPoco, 'Reward')
.withArgs(kittyAddress, kittyFillingSchedulerTaskStake, kittyFillingDeal.taskId)
.to.emit(iexecPoco, 'Lock')
.withArgs(kittyAddress, kittyFillingSchedulerTaskStake);
const kittyFrozenAfterClaim = (await iexecPoco.frozenOf(kittyAddress)).toNumber();
expect(kittyFrozenAfterClaim).to.equal(
kittyFrozenBeforeClaim + kittyFillingSchedulerTaskStake,
Expand Down Expand Up @@ -579,6 +575,11 @@ describe('IexecPoco2#finalize', async () => {
.reveal(taskId, resultDigest)
.then((tx) => tx.wait());
await expect(iexecPocoAsScheduler.finalize(taskId, results, '0x'))
.to.changeTokenBalances(
iexecPoco,
[iexecPoco, scheduler, kittyAddress],
[-expectedSchedulerKittyPartReward, expectedSchedulerKittyPartReward, 0],
)
.to.emit(iexecPoco, 'TaskFinalize')
.to.emit(iexecPoco, 'Seize')
.withArgs(kittyAddress, expectedSchedulerKittyPartReward, taskId)
Expand All @@ -589,12 +590,7 @@ describe('IexecPoco2#finalize', async () => {
expectedSchedulerKittyPartReward,
)
.to.emit(iexecPoco, 'Reward')
.withArgs(scheduler.address, expectedSchedulerKittyPartReward, taskId)
.to.changeTokenBalances(
iexecPoco,
[iexecPoco, scheduler, kittyAddress],
[-expectedSchedulerKittyPartReward, expectedSchedulerKittyPartReward, 0],
);
.withArgs(scheduler.address, expectedSchedulerKittyPartReward, taskId);
expect(await iexecPoco.frozenOf(kittyAddress)).to.equal(
kittyFrozenAfterClaim - expectedSchedulerKittyPartReward,
);
Expand Down
4 changes: 0 additions & 4 deletions test/byContract/IexecPoco/06_claim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,8 @@ describe('IexecPoco2#claim', async () => {
.withArgs(sponsor.address, taskPrice)
.to.emit(iexecPoco, 'Seize')
.withArgs(scheduler.address, schedulerTaskStake, taskId)
.to.emit(iexecPoco, 'Transfer')
.withArgs(iexecPoco.address, kittyAddress, schedulerTaskStake)
.to.emit(iexecPoco, 'Reward')
.withArgs(kittyAddress, schedulerTaskStake, taskId)
.to.emit(iexecPoco, 'Transfer')
.withArgs(kittyAddress, iexecPoco.address, schedulerTaskStake)
.to.emit(iexecPoco, 'Lock')
.withArgs(kittyAddress, schedulerTaskStake);
for (const worker of workers) {
Expand Down

0 comments on commit 5ef8455

Please sign in to comment.