-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
staking: allocate use channel public key #190
Conversation
contracts/Staking.sol
Outdated
require(isChannel(_channelID) == false, "Allocation: channel ID already in use"); | ||
// Cannot reuse a channelID that has been used in the past | ||
/* prettier-ignore */ | ||
address channelID = publicKeyToAddress(bytes(_channelPubKey[1:])); // solium-disable-line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you manage to verify that this is correct?
Two examples:
Public key 0x03a74c72b51f4d36e9e4a13616dddeae31bafe41b1662804476a6859e26d9c734f
Results in address: 0xcFFAc3084674cc596F1F91c16f8FBc2De16B3DC8
Public key 0x036b7b0e7896e59a8b9e0a940e25d253b18a25fefba08da3eeb19a25839ba65eea
Results in address: 0x72b7e00027212AEEe61B88d6aE714f278220b595
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've verified that we can go from the public key to the Connext channel identifier, so I can confirm that channelID
/ signer address and public key are all I need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I verified it is working on the tests in test/staking/general.test.js
I used:
- Public Key '0x0456708870bfd5d8fc956fe33285dcf59b075cd7a25a21ee00834e480d3754bcda180e670145a290bb4bebca8e105ea7776a7b39e16c4df7d4d1083260c6f05d53'
- Address: '0x6367E9dD7641e0fF221740b57B8C730031d72530'
@Jannis note that the public key is in uncompressed format for Solidity to easily convert to address
Snippet on how to do that:
const publicKey = '0x026655feed4d214c261e0a6b554395596f1f1476a77d999560e5a8df9b8a1a3515';
let compressedPublicKey = ethers.utils.computePublicKey(publicKey, true);
let uncompressedPublicKey = ethers.utils.computePublicKey(publicKey, false);
console.log(compressedPublicKey);
// "0x026655feed4d214c261e0a6b554395596f1f1476a77d999560e5a8df9b8a1a3515"
console.log(uncompressedPublicKey);
// "0x046655feed4d214c261e0a6b554395596f1f1476a77d999560e5a8df9b8a1a35" +
// "15217e88dd05e938efdd71b2cce322bf01da96cd42087b236e8f5043157a9c068e"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jannis let me know if you are ok with the response so we can merge
test/staking/general.test.js
Outdated
@@ -159,6 +159,9 @@ contract('Staking', ([me, other, governor, indexNode, channelOwner]) => { | |||
describe('staking', function() { | |||
beforeEach(async function() { | |||
this.subgraphId = helpers.randomSubgraphIdHex0x() | |||
this.channelPubKey = | |||
'0x0456708870bfd5d8fc956fe33285dcf59b075cd7a25a21ee00834e480d3754bcda180e670145a290bb4bebca8e105ea7776a7b39e16c4df7d4d1083260c6f05d53' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this key here is an extended public key? It's much longer than a regular public key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just see this comment and posted an explanation in the comment before.
It's called uncompressed public key format. I posted a snippet using the ethers library on how to convert from one public key format to the other.
I committed just one more change to bump to the newest version of solidity-prettier. They fixed the issue I reported. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, i made one small note on a comment
contracts/Staking.sol
Outdated
require( | ||
stake.tokensAvailable() >= _tokens, | ||
"Allocation: not enough tokens available to allocate" | ||
); | ||
// Only can allocate tokens to a subgraph if not currently allocated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only can => Can only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed and rebased!
c8c9d20
to
e41de1e
Compare
…culate Ethereum address of the channel signer using the public key
…that linter does not support
…st version and remove prettier ignore line
e41de1e
to
c4d3e4e
Compare
Allocate()
advertises the public key in the AllocationCreated event so we can capture in our Network Subgraph, using that information consumers can route payments to the index node.Allocate()
calculates the signer address of the index node in the payment channel by getting the Ethereum address from the public key.NOTE:
Reported issues to both projects: