Skip to content

Commit 9c2854a

Browse files
committed
staking: remove channel references
1 parent c0bf0d3 commit 9c2854a

File tree

2 files changed

+81
-77
lines changed

2 files changed

+81
-77
lines changed

contracts/disputes/DisputeManager.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,11 @@ contract DisputeManager is Governed {
430430
// Decode attestation
431431
Attestation memory attestation = _parseAttestation(_attestationData);
432432

433-
// Get attestation signer, channelID
434-
address channelID = _recoverAttestationSigner(attestation);
433+
// Get attestation signer, allocationID
434+
address allocationID = _recoverAttestationSigner(attestation);
435435

436-
// Get the indexer that created the channel and signed the attestation
437-
IStaking.Allocation memory alloc = staking.getAllocation(channelID);
436+
// Get the indexer that created the allocation and signed the attestation
437+
IStaking.Allocation memory alloc = staking.getAllocation(allocationID);
438438
require(alloc.indexer != address(0), "Indexer cannot be found for the attestation");
439439
require(
440440
alloc.subgraphDeploymentID == attestation.subgraphDeploymentID,

contracts/staking/Staking.sol

Lines changed: 77 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking, Governed {
9797
/**
9898
* @dev Emitted when `indexer` allocated `tokens` amount to `subgraphDeploymentID`
9999
* during `epoch`.
100-
* `channelID` is the address of the indexer in the channel multisig.
100+
* `allocationID` indexer derived address used to identify the allocation.
101101
* `channelPubKey` is the public key used for routing payments to the indexer channel.
102102
* `price` price the `indexer` will charge for serving queries of the `subgraphDeploymentID`.
103103
*/
@@ -106,14 +106,14 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking, Governed {
106106
bytes32 indexed subgraphDeploymentID,
107107
uint256 epoch,
108108
uint256 tokens,
109-
address channelID,
109+
address allocationID,
110110
bytes channelPubKey,
111111
uint256 price,
112112
address proxy
113113
);
114114

115115
/**
116-
* @dev Emitted when `indexer` withdrew `tokens` amount in `epoch` from `channelID` channel.
116+
* @dev Emitted when `indexer` withdrew `tokens` amount in `epoch` from `allocationID` channel.
117117
* The funds are related to `subgraphDeploymentID`.
118118
* `from` attribute records the the multisig contract from where it was settled.
119119
*/
@@ -122,14 +122,14 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking, Governed {
122122
bytes32 indexed subgraphDeploymentID,
123123
uint256 epoch,
124124
uint256 tokens,
125-
address channelID,
125+
address allocationID,
126126
address from,
127127
uint256 curationFees,
128128
uint256 rebateFees
129129
);
130130

131131
/**
132-
* @dev Emitted when `indexer` settled an allocation in `epoch` for `channelID` channel.
132+
* @dev Emitted when `indexer` settled an allocation in `epoch` for `allocationID` channel.
133133
* The `tokens` getting unallocated from `subgraphDeploymentID`.
134134
* The `effectiveAllocation` are the tokens allocated from creation to settlement.
135135
*/
@@ -138,7 +138,7 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking, Governed {
138138
bytes32 indexed subgraphDeploymentID,
139139
uint256 epoch,
140140
uint256 tokens,
141-
address channelID,
141+
address allocationID,
142142
uint256 effectiveAllocation,
143143
address sender
144144
);
@@ -152,7 +152,7 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking, Governed {
152152
event RebateClaimed(
153153
address indexed indexer,
154154
bytes32 indexed subgraphDeploymentID,
155-
address channelID,
155+
address allocationID,
156156
uint256 epoch,
157157
uint256 forEpoch,
158158
uint256 tokens,
@@ -265,7 +265,7 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking, Governed {
265265
}
266266

267267
/**
268-
* @dev Set the max allocation time allowed for indexers stake on channels.
268+
* @dev Set the max time allowed for indexers stake on allocations.
269269
* @param _maxAllocationEpochs Allocation duration limit in epochs
270270
*/
271271
function setMaxAllocationEpochs(uint32 _maxAllocationEpochs) external override onlyGovernor {
@@ -375,12 +375,12 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking, Governed {
375375
}
376376

377377
/**
378-
* @dev Return if channelID (address) was used as a channel in any allocation.
379-
* @param _channelID Address used as signer for indexer in channel
380-
* @return True if channelID already used
378+
* @dev Return if allocationID is used.
379+
* @param _allocationID Address used as signer by the indexer for an allocation
380+
* @return True if allocationID already used
381381
*/
382-
function isChannel(address _channelID) external override view returns (bool) {
383-
return _getAllocationState(_channelID) != AllocationState.Null;
382+
function isChannel(address _allocationID) external override view returns (bool) {
383+
return _getAllocationState(_allocationID) != AllocationState.Null;
384384
}
385385

386386
/**
@@ -393,26 +393,31 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking, Governed {
393393
}
394394

395395
/**
396-
* @dev Return the allocation for a particular channel identifier.
397-
* @param _channelID Address used as channel identifier where stake has been allocated
396+
* @dev Return the allocation by ID.
397+
* @param _allocationID Address used as allocation identifier
398398
* @return Allocation data
399399
*/
400-
function getAllocation(address _channelID) external override view returns (Allocation memory) {
401-
return allocations[_channelID];
400+
function getAllocation(address _allocationID)
401+
external
402+
override
403+
view
404+
returns (Allocation memory)
405+
{
406+
return allocations[_allocationID];
402407
}
403408

404409
/**
405410
* @dev Return the current state of an allocation.
406-
* @param _channelID Address used as the allocation channel identifier
411+
* @param _allocationID Address used as the allocation identifier
407412
* @return AllocationState
408413
*/
409-
function getAllocationState(address _channelID)
414+
function getAllocationState(address _allocationID)
410415
external
411416
override
412417
view
413418
returns (AllocationState)
414419
{
415-
return _getAllocationState(_channelID);
420+
return _getAllocationState(_allocationID);
416421
}
417422

418423
/**
@@ -748,16 +753,16 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking, Governed {
748753
}
749754

750755
/**
751-
* @dev Settle a channel and unallocate the staked tokens.
752-
* @param _channelID The channel identifier for the allocation
756+
* @dev Settle an allocation and free the staked tokens.
757+
* @param _allocationID The allocation identifier
753758
*/
754-
function settle(address _channelID) external override {
755-
// Get allocation related to the channel identifier
756-
Allocation storage alloc = allocations[_channelID];
757-
AllocationState allocState = _getAllocationState(_channelID);
759+
function settle(address _allocationID) external override {
760+
// Get allocation
761+
Allocation storage alloc = allocations[_allocationID];
762+
AllocationState allocState = _getAllocationState(_allocationID);
758763

759764
// Channel must exist and be allocated
760-
require(allocState == AllocationState.Active, "Settle: channel must be active");
765+
require(allocState == AllocationState.Active, "Settle: allocation must be active");
761766

762767
// Get indexer stakes
763768
Stakes.Indexer storage indexerStake = stakes[alloc.indexer];
@@ -779,7 +784,7 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking, Governed {
779784
}
780785

781786
// Settle the allocation and start counting a period to finalize any other
782-
// withdrawal from the related channel.
787+
// withdrawal for the allocation.
783788
alloc.settledAtEpoch = currentEpoch;
784789
alloc.effectiveAllocation = _getEffectiveAllocation(alloc.tokens, epochs);
785790

@@ -795,28 +800,27 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking, Governed {
795800
alloc.subgraphDeploymentID,
796801
alloc.settledAtEpoch,
797802
alloc.tokens,
798-
_channelID,
803+
_allocationID,
799804
alloc.effectiveAllocation,
800805
msg.sender
801806
);
802807
}
803808

804809
/**
805-
* @dev Collect query fees from a channel.
806-
* Funds received are only accepted from a channel multisig proxy contract.
810+
* @dev Collect query fees for an allocation.
811+
* Funds received are only accepted from a valid source.
807812
* @param _tokens Amount of tokens to collect
808813
*/
809-
function collect(uint256 _tokens, address _channelID) external override {
810-
Allocation memory alloc = allocations[_channelID];
814+
function collect(uint256 _tokens, address _allocationID) external override {
815+
Allocation memory alloc = allocations[_allocationID];
811816

812-
// Channel identifier validation
813-
require(_channelID != address(0), "Collect: invalid channel");
817+
// Allocation identifier validation
818+
require(_allocationID != address(0), "Collect: invalid allocation");
814819

815820
// The contract caller must be a channel proxy registered during allocation
816-
// The channelID must be related to the caller address
817821
require(
818822
alloc.channelProxy == msg.sender,
819-
"Collect: caller is not related to the channel allocation"
823+
"Collect: caller is not related to the allocation"
820824
);
821825

822826
// Transfer tokens to collect from multisig to this contract
@@ -825,26 +829,26 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking, Governed {
825829
"Collect: cannot transfer tokens to settle"
826830
);
827831

828-
_collect(_channelID, msg.sender, _tokens);
832+
_collect(_allocationID, msg.sender, _tokens);
829833
}
830834

831835
/**
832836
* @dev Claim tokens from the rebate pool.
833-
* @param _channelID Identifier of the channel we are claiming funds from
837+
* @param _allocationID Allocation from where we are claiming tokens
834838
* @param _restake True if restake fees instead of transfer to indexer
835839
*/
836-
function claim(address _channelID, bool _restake) external override {
837-
// Get allocation related to the channel identifier
838-
Allocation storage alloc = allocations[_channelID];
839-
AllocationState allocState = _getAllocationState(_channelID);
840+
function claim(address _allocationID, bool _restake) external override {
841+
// Get allocation
842+
Allocation storage alloc = allocations[_allocationID];
843+
AllocationState allocState = _getAllocationState(_allocationID);
840844

841845
// Validate ownership
842846
require(_onlyAuthOrDelegator(alloc.indexer), "Rebate: caller must be authorized");
843847

844848
// Funds can only be claimed after a period of time passed since settlement
845849
require(
846850
allocState == AllocationState.Finalized,
847-
"Rebate: channel must be in finalized state"
851+
"Rebate: allocation must be in finalized state"
848852
);
849853

850854
// Find a rebate pool for the settled epoch
@@ -862,8 +866,8 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking, Governed {
862866
uint256 delegationFees = _collectDelegationFees(alloc.indexer, tokensToClaim);
863867
tokensToClaim = tokensToClaim.sub(delegationFees);
864868

865-
// Purgue allocation data except for:
866-
// - indexer: used in disputes and to avoid reusing a channelID
869+
// Purge allocation data except for:
870+
// - indexer: used in disputes and to avoid reusing an allocationID
867871
// - subgraphDeploymentID: used in disputes
868872
uint256 settledAtEpoch = alloc.settledAtEpoch;
869873
alloc.tokens = 0; // This avoid collect(), settle() and claim() to be called
@@ -891,7 +895,7 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking, Governed {
891895
emit RebateClaimed(
892896
alloc.indexer,
893897
alloc.subgraphDeploymentID,
894-
_channelID,
898+
_allocationID,
895899
epochManager.currentEpoch(),
896900
settledAtEpoch,
897901
tokensToClaim,
@@ -959,27 +963,27 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking, Governed {
959963
// Get the Ethereum address from the public key and use as channel identifier.
960964
// The channel identifier is the address of the indexer signing party of a multisig that
961965
// will hold the funds received when the channel is settled.
962-
address channelID = address(uint256(keccak256(_sliceByte(bytes(_channelPubKey)))));
966+
address allocationID = address(uint256(keccak256(_sliceByte(bytes(_channelPubKey)))));
963967

964-
// Cannot reuse a channelID that has already been used in an allocation
968+
// Cannot reuse an allocationID that has already been used in an allocation
965969
require(
966-
_getAllocationState(channelID) == AllocationState.Null,
967-
"Allocation: channel ID already used"
970+
_getAllocationState(allocationID) == AllocationState.Null,
971+
"Allocation: allocation ID already used"
968972
);
969973

970-
// Create allocation linked to the channel identifier
971-
// Channel identifiers are not reused
974+
// Creates an allocation
975+
// Allocation identifiers are not reused
972976
// The channel proxy address is the contract that will send tokens to be collected to
973977
// this contract
974-
allocations[channelID] = Allocation(
978+
allocations[allocationID] = Allocation(
975979
_indexer,
976980
_subgraphDeploymentID,
977981
_tokens, // Tokens allocated
978982
epochManager.currentEpoch(), // createdAtEpoch
979983
0, // settledAtEpoch
980984
0, // Initialize with zero collected fees
981985
0, // Initialize effective allocation
982-
_channelProxy // Source address of channel funds
986+
_channelProxy // Source address of allocation collected funds
983987
);
984988

985989
// Mark allocated tokens as used
@@ -988,36 +992,36 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking, Governed {
988992
emit AllocationCreated(
989993
_indexer,
990994
_subgraphDeploymentID,
991-
allocations[channelID].createdAtEpoch,
992-
allocations[channelID].tokens,
993-
channelID,
995+
allocations[allocationID].createdAtEpoch,
996+
allocations[allocationID].tokens,
997+
allocationID,
994998
_channelPubKey,
995999
_price,
9961000
_channelProxy
9971001
);
9981002
}
9991003

10001004
/**
1001-
* @dev Withdraw and collect funds from the channel.
1002-
* @param _channelID ChannelID address of the indexer in the channel
1003-
* @param _from Multisig channel address that triggered withdrawal
1005+
* @dev Withdraw and collect funds for an allocation.
1006+
* @param _allocationID Allocation that is receiving collected funds
1007+
* @param _from Source of collected funds for the allocation
10041008
* @param _tokens Amount of tokens to withdraw
10051009
*/
10061010
function _collect(
1007-
address _channelID,
1011+
address _allocationID,
10081012
address _from,
10091013
uint256 _tokens
10101014
) private {
10111015
uint256 rebateFees = _tokens;
10121016

1013-
// Get allocation related to the channel identifier
1014-
Allocation storage alloc = allocations[_channelID];
1015-
AllocationState allocState = _getAllocationState(_channelID);
1017+
// Get allocation
1018+
Allocation storage alloc = allocations[_allocationID];
1019+
AllocationState allocState = _getAllocationState(_allocationID);
10161020

1017-
// The channel must be active or settled
1021+
// The allocation must be active or settled
10181022
require(
10191023
allocState == AllocationState.Active || allocState == AllocationState.Settled,
1020-
"Collect: channel must be active or settled"
1024+
"Collect: allocation must be active or settled"
10211025
);
10221026

10231027
// Collect protocol fees to be burned
@@ -1028,10 +1032,10 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking, Governed {
10281032
uint256 curationFees = _collectCurationFees(alloc.subgraphDeploymentID, rebateFees);
10291033
rebateFees = rebateFees.sub(curationFees);
10301034

1031-
// Collect funds in the allocated channel
1035+
// Collect funds for the allocation
10321036
alloc.collectedFees = alloc.collectedFees.add(rebateFees);
10331037

1034-
// When channel allocation is settled redirect funds to the rebate pool
1038+
// When allocation is settled redirect funds to the rebate pool
10351039
if (allocState == AllocationState.Settled) {
10361040
Rebates.Pool storage rebatePool = rebates[alloc.settledAtEpoch];
10371041
rebatePool.fees = rebatePool.fees.add(rebateFees);
@@ -1053,7 +1057,7 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking, Governed {
10531057
alloc.subgraphDeploymentID,
10541058
epochManager.currentEpoch(),
10551059
_tokens,
1056-
_channelID,
1060+
_allocationID,
10571061
_from,
10581062
curationFees,
10591063
rebateFees
@@ -1195,11 +1199,11 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking, Governed {
11951199

11961200
/**
11971201
* @dev Return the current state of an allocation
1198-
* @param _channelID Address used as the allocation channel identifier
1202+
* @param _allocationID Allocation identifier
11991203
* @return AllocationState
12001204
*/
1201-
function _getAllocationState(address _channelID) private view returns (AllocationState) {
1202-
Allocation memory alloc = allocations[_channelID];
1205+
function _getAllocationState(address _allocationID) private view returns (AllocationState) {
1206+
Allocation memory alloc = allocations[_allocationID];
12031207

12041208
if (alloc.indexer == address(0)) {
12051209
return AllocationState.Null;

0 commit comments

Comments
 (0)