Skip to content

Commit d3576ce

Browse files
committed
staking: remove channel public key from the allocate call and pass the allocationID. It was used to emit in the AllocationCreated event to allow for clients to route payments but now is deprecated.
1 parent c9ff22d commit d3576ce

File tree

9 files changed

+61
-123
lines changed

9 files changed

+61
-123
lines changed

cli/commands/contracts/staking.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const withdraw = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<v
3333
export const allocate = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => {
3434
const subgraphDeploymentID = cliArgs.subgraphDeploymentID
3535
const amount = parseGRT(cliArgs.amount)
36-
const channelPubKey = cliArgs.channelPubKey
36+
const allocationID = cliArgs.allocationID
3737
const assetHolder = cliArgs.assetHolder
3838
const metadata = cliArgs.metadata
3939
const staking = cli.contracts.Staking
@@ -43,7 +43,7 @@ export const allocate = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<v
4343
cli.wallet,
4444
staking,
4545
'allocate',
46-
...[subgraphDeploymentID, amount, channelPubKey, assetHolder, metadata],
46+
...[subgraphDeploymentID, amount, allocationID, assetHolder, metadata],
4747
)
4848
}
4949

@@ -184,8 +184,8 @@ export const stakingCommand = {
184184
requiresArg: true,
185185
demandOption: true,
186186
})
187-
.option('channelPubKey', {
188-
description: 'The public key used by the indexer to setup the off-chain channel',
187+
.option('allocationID', {
188+
description: 'Address used by the indexer as destination of funds of state channel',
189189
type: 'string',
190190
requiresArg: true,
191191
demandOption: true,

contracts/staking/IStaking.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ interface IStaking {
117117
function allocate(
118118
bytes32 _subgraphDeploymentID,
119119
uint256 _tokens,
120-
bytes calldata _channelPubKey,
120+
address _allocationID,
121121
address _assetHolder,
122122
bytes32 _metadata
123123
) external;
@@ -126,7 +126,7 @@ interface IStaking {
126126
address _indexer,
127127
bytes32 _subgraphDeploymentID,
128128
uint256 _tokens,
129-
bytes calldata _channelPubKey,
129+
address _allocationID,
130130
address _assetHolder,
131131
bytes32 _metadata
132132
) external;
@@ -139,7 +139,7 @@ interface IStaking {
139139
address _indexer,
140140
bytes32 _subgraphDeploymentID,
141141
uint256 _tokens,
142-
bytes calldata _channelPubKey,
142+
address _allocationID,
143143
address _assetHolder,
144144
bytes32 _metadata
145145
) external;

contracts/staking/Staking.sol

Lines changed: 16 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
9393
* @dev Emitted when `indexer` allocated `tokens` amount to `subgraphDeploymentID`
9494
* during `epoch`.
9595
* `allocationID` indexer derived address used to identify the allocation.
96-
* `channelPubKey` is the public key used for routing payments to the indexer channel.
9796
* `metadata` additional information related to the allocation.
9897
*/
9998
event AllocationCreated(
@@ -102,7 +101,6 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
102101
uint256 epoch,
103102
uint256 tokens,
104103
address allocationID,
105-
bytes channelPubKey,
106104
bytes32 metadata,
107105
address assetHolder
108106
);
@@ -684,22 +682,22 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
684682
* @dev Allocate available tokens to a subgraph deployment.
685683
* @param _subgraphDeploymentID ID of the SubgraphDeployment where tokens will be allocated
686684
* @param _tokens Amount of tokens to allocate
687-
* @param _channelPubKey The public key used to route payments
685+
* @param _allocationID The allocation identifier
688686
* @param _assetHolder Authorized sender address of collected funds
689687
* @param _metadata IPFS hash for additional information about the allocation
690688
*/
691689
function allocate(
692690
bytes32 _subgraphDeploymentID,
693691
uint256 _tokens,
694-
bytes calldata _channelPubKey,
692+
address _allocationID,
695693
address _assetHolder,
696694
bytes32 _metadata
697695
) external override notPaused {
698696
_allocate(
699697
msg.sender,
700698
_subgraphDeploymentID,
701699
_tokens,
702-
_channelPubKey,
700+
_allocationID,
703701
_assetHolder,
704702
_metadata
705703
);
@@ -710,26 +708,19 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
710708
* @param _indexer Indexer address to allocate funds from.
711709
* @param _subgraphDeploymentID ID of the SubgraphDeployment where tokens will be allocated
712710
* @param _tokens Amount of tokens to allocate
713-
* @param _channelPubKey The public key used to route payments
711+
* @param _allocationID The allocation identifier
714712
* @param _assetHolder Authorized sender address of collected funds
715713
* @param _metadata IPFS hash for additional information about the allocation
716714
*/
717715
function allocateFrom(
718716
address _indexer,
719717
bytes32 _subgraphDeploymentID,
720718
uint256 _tokens,
721-
bytes calldata _channelPubKey,
719+
address _allocationID,
722720
address _assetHolder,
723721
bytes32 _metadata
724722
) external override notPaused {
725-
_allocate(
726-
_indexer,
727-
_subgraphDeploymentID,
728-
_tokens,
729-
_channelPubKey,
730-
_assetHolder,
731-
_metadata
732-
);
723+
_allocate(_indexer, _subgraphDeploymentID, _tokens, _allocationID, _assetHolder, _metadata);
733724
}
734725

735726
/**
@@ -752,7 +743,7 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
752743
* @param _indexer Indexer address to allocate funds from.
753744
* @param _subgraphDeploymentID ID of the SubgraphDeployment where tokens will be allocated
754745
* @param _tokens Amount of tokens to allocate
755-
* @param _channelPubKey The public key used to route payments
746+
* @param _allocationID The allocation identifier
756747
* @param _assetHolder Authorized sender address of collected funds
757748
* @param _metadata IPFS hash for additional information about the allocation
758749
*/
@@ -762,19 +753,12 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
762753
address _indexer,
763754
bytes32 _subgraphDeploymentID,
764755
uint256 _tokens,
765-
bytes calldata _channelPubKey,
756+
address _allocationID,
766757
address _assetHolder,
767758
bytes32 _metadata
768759
) external override notPaused {
769760
_closeAllocation(_closingAllocationID, _poi);
770-
_allocate(
771-
_indexer,
772-
_subgraphDeploymentID,
773-
_tokens,
774-
_channelPubKey,
775-
_assetHolder,
776-
_metadata
777-
);
761+
_allocate(_indexer, _subgraphDeploymentID, _tokens, _allocationID, _assetHolder, _metadata);
778762
}
779763

780764
/**
@@ -901,15 +885,15 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
901885
* @param _indexer Indexer address to allocate funds from.
902886
* @param _subgraphDeploymentID ID of the SubgraphDeployment where tokens will be allocated
903887
* @param _tokens Amount of tokens to allocate
904-
* @param _channelPubKey The public key used by the indexer to setup the off-chain channel
888+
* @param _allocationID The allocationID will work to identify collected funds related to this allocation
905889
* @param _assetHolder Authorized sender address of collected funds
906890
* @param _metadata Metadata related to the allocation
907891
*/
908892
function _allocate(
909893
address _indexer,
910894
bytes32 _subgraphDeploymentID,
911895
uint256 _tokens,
912-
bytes memory _channelPubKey,
896+
address _allocationID,
913897
address _assetHolder,
914898
bytes32 _metadata
915899
) internal {
@@ -920,23 +904,15 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
920904
// Only allocations with a non-zero token amount are allowed
921905
require(_tokens > 0, "Cannot allocate zero tokens");
922906

923-
// Channel public key must be in uncompressed format
924-
require(
925-
uint8(_channelPubKey[0]) == 4 && _channelPubKey.length == 65,
926-
"Invalid channel public key"
927-
);
907+
// Check allocation ID
908+
require(_allocationID != address(0), "Invalid allocationID");
928909

929910
// Needs to have free capacity not used for other purposes to allocate
930911
require(getIndexerCapacity(_indexer) >= _tokens, "Not enough tokens available to allocate");
931912

932-
// A channel public key is derived by the indexer when creating the offchain payment channel.
933-
// Get the Ethereum address from the public key and use as allocation identifier.
934-
// The allocationID will work to identify collected funds related to this allocation.
935-
address allocationID = address(uint256(keccak256(_sliceByte(bytes(_channelPubKey)))));
936-
937913
// Cannot reuse an allocationID that has already been used in an allocation
938914
require(
939-
_getAllocationState(allocationID) == AllocationState.Null,
915+
_getAllocationState(_allocationID) == AllocationState.Null,
940916
"AllocationID already used"
941917
);
942918

@@ -954,7 +930,7 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
954930
_assetHolder, // Source address for allocation collected funds
955931
_updateRewards(_subgraphDeploymentID) // Initialize accumulated rewards per stake allocated
956932
);
957-
allocations[allocationID] = alloc;
933+
allocations[_allocationID] = alloc;
958934

959935
// Mark allocated tokens as used
960936
indexerStake.allocate(alloc.tokens);
@@ -970,8 +946,7 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
970946
_subgraphDeploymentID,
971947
alloc.createdAtEpoch,
972948
alloc.tokens,
973-
allocationID,
974-
_channelPubKey,
949+
_allocationID,
975950
_metadata,
976951
_assetHolder
977952
);
@@ -1309,38 +1284,6 @@ contract Staking is StakingV1Storage, GraphUpgradeable, IStaking {
13091284
return _tokens.mul((shouldCap) ? maxAllocationEpochs : _numEpochs);
13101285
}
13111286

1312-
/**
1313-
* @dev Removes the first byte from a bytes array.
1314-
* @param _bytes Byte array to slice
1315-
* @return New bytes array
1316-
*/
1317-
function _sliceByte(bytes memory _bytes) internal pure returns (bytes memory) {
1318-
bytes memory tempBytes;
1319-
uint256 length = _bytes.length - 1;
1320-
1321-
assembly {
1322-
tempBytes := mload(0x40)
1323-
1324-
let lengthmod := and(length, 31)
1325-
let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod)))
1326-
let end := add(mc, length)
1327-
1328-
for {
1329-
let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), 1)
1330-
} lt(mc, end) {
1331-
mc := add(mc, 0x20)
1332-
cc := add(cc, 0x20)
1333-
} {
1334-
mstore(mc, mload(cc))
1335-
}
1336-
1337-
mstore(tempBytes, length)
1338-
mstore(0x40, and(add(mc, 31), not(31)))
1339-
}
1340-
1341-
return tempBytes;
1342-
}
1343-
13441287
/**
13451288
* @dev Triggers an update of rewards due to a change in allocations.
13461289
* @param _subgraphDeploymentID Subgrapy deployment updated

test/disputes/poi.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ describe('DisputeManager:POI', async () => {
5353
// Dispute manager is allowed to slash
5454
await staking.connect(governor.signer).setSlasher(disputeManager.address, true)
5555

56-
// Stake
57-
const indexerList = [{ wallet: indexer, pubKey: indexerChannelKey.pubKey }]
56+
// Stake & allocate
57+
const indexerList = [{ wallet: indexer, allocationID: indexerChannelKey.address }]
5858
for (const activeIndexer of indexerList) {
5959
const indexerWallet = activeIndexer.wallet
60-
const indexerPubKey = activeIndexer.pubKey
60+
const indexerAllocationID = activeIndexer.allocationID
6161

6262
// Give some funds to the indexer
6363
await grt.connect(governor.signer).mint(indexerWallet.address, indexerTokens)
@@ -70,7 +70,7 @@ describe('DisputeManager:POI', async () => {
7070
.allocate(
7171
subgraphDeploymentID,
7272
indexerAllocatedTokens,
73-
indexerPubKey,
73+
indexerAllocationID,
7474
assetHolder.address,
7575
metadata,
7676
)
@@ -144,7 +144,7 @@ describe('DisputeManager:POI', async () => {
144144
.allocate(
145145
subgraphDeploymentID,
146146
indexerAllocatedTokens,
147-
indexerChannelKey.pubKey,
147+
allocationID,
148148
assetHolder.address,
149149
metadata,
150150
)

test/disputes/query.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ describe('DisputeManager:Query', async () => {
114114

115115
// Stake
116116
const indexerList = [
117-
{ wallet: indexer, pubKey: indexer1ChannelKey.pubKey },
118-
{ wallet: indexer2, pubKey: indexer2ChannelKey.pubKey },
117+
{ wallet: indexer, allocationID: indexer1ChannelKey.address },
118+
{ wallet: indexer2, allocationID: indexer2ChannelKey.address },
119119
]
120120
for (const activeIndexer of indexerList) {
121121
const indexerWallet = activeIndexer.wallet
122-
const indexerPubKey = activeIndexer.pubKey
122+
const indexerAllocationID = activeIndexer.allocationID
123123

124124
// Give some funds to the indexer
125125
await grt.connect(governor.signer).mint(indexerWallet.address, indexerTokens)
@@ -132,7 +132,7 @@ describe('DisputeManager:Query', async () => {
132132
.allocate(
133133
dispute.receipt.subgraphDeploymentID,
134134
indexerAllocatedTokens,
135-
indexerPubKey,
135+
indexerAllocationID,
136136
assetHolder.address,
137137
metadata,
138138
)
@@ -216,7 +216,7 @@ describe('DisputeManager:Query', async () => {
216216
.allocate(
217217
dispute.receipt.subgraphDeploymentID,
218218
indexerAllocatedTokens,
219-
indexer1ChannelKey.pubKey,
219+
indexer1ChannelKey.address,
220220
assetHolder.address,
221221
metadata,
222222
)
@@ -433,11 +433,11 @@ describe('DisputeManager:Query', async () => {
433433
.withArgs(dispute.id, dispute.indexerAddress, fisherman.address, fishermanDeposit)
434434

435435
// After state
436-
const afterTishermanBalance = await grt.balanceOf(fisherman.address)
436+
const afterFishermanBalance = await grt.balanceOf(fisherman.address)
437437
const afterTotalSupply = await grt.totalSupply()
438438

439439
// No change in fisherman balance
440-
expect(afterTishermanBalance).eq(beforeFishermanBalance)
440+
expect(afterFishermanBalance).eq(beforeFishermanBalance)
441441
// Burn fisherman deposit
442442
const burnedTokens = fishermanDeposit
443443
expect(afterTotalSupply).eq(beforeTotalSupply.sub(burnedTokens))

test/rewards/rewards.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ describe('Rewards', () => {
4949
const subgraphDeploymentID1 = randomHexBytes()
5050
const subgraphDeploymentID2 = randomHexBytes()
5151
const allocationID = '0x6367E9dD7641e0fF221740b57B8C730031d72530'
52-
const channelPubKey =
53-
'0x0456708870bfd5d8fc956fe33285dcf59b075cd7a25a21ee00834e480d3754bcda180e670145a290bb4bebca8e105ea7776a7b39e16c4df7d4d1083260c6f05d53'
5452
const metadata = HashZero
5553

5654
const ISSUANCE_RATE_PERIODS = 4 // blocks required to issue 5% rewards
@@ -380,7 +378,7 @@ describe('Rewards', () => {
380378
.allocate(
381379
subgraphDeploymentID1,
382380
tokensToAllocate,
383-
channelPubKey,
381+
allocationID,
384382
assetHolder.address,
385383
metadata,
386384
)
@@ -417,7 +415,7 @@ describe('Rewards', () => {
417415
.allocate(
418416
subgraphDeploymentID1,
419417
tokensToAllocate,
420-
channelPubKey,
418+
allocationID,
421419
assetHolder.address,
422420
metadata,
423421
)
@@ -460,7 +458,7 @@ describe('Rewards', () => {
460458
.allocate(
461459
subgraphDeploymentID1,
462460
tokensToAllocate,
463-
channelPubKey,
461+
allocationID,
464462
assetHolder.address,
465463
metadata,
466464
)
@@ -524,7 +522,7 @@ describe('Rewards', () => {
524522
.allocate(
525523
subgraphDeploymentID1,
526524
tokensToAllocate,
527-
channelPubKey,
525+
allocationID,
528526
assetHolder.address,
529527
metadata,
530528
)

0 commit comments

Comments
 (0)