-
Notifications
You must be signed in to change notification settings - Fork 16
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
adding experiment with self calls #401
Conversation
Terraform Feature Environment (dev-401)Terraform Initialization ⚙️
|
contract/src/lib.rs
Outdated
None => { | ||
env::log_str("not ready"); | ||
let account_id = env::current_account_id(); | ||
PromiseOrValue::Promise(Self::ext(account_id).sign_helper(payload_id)) |
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.
Would it be possible to extend the delay for longer, for cheaper, by chaining 1-yocto transfers before the reflexive call, especially if a minimum delay is expected?
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.
How would chaining 1-yotco transfers help?
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 think the assumption here is that 1-yocto transfer is cheaper than a cross-contract call
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.
Maybe I am missing something here but I think you still have to call self again in order to continuously check whether a signature has been generated.
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.
Yeah, so I think what @encody means is that we could explore whether it makes sense to chain 10 1-yocto transfers first to create cheap superficial delay since we know that the response is not going to arrive in the first ~10 seconds (or whatever constant makes sense here), and then chain self-calls afterward expecting the response to have potentially come in by then.
|
Never mind the above, I figured out what the problem was. I just wasn't indexing txs that return receipt ids properly. From what I am seeing so far the approach works. I am getting a ton of timeout errors, but I think most of them are happening due to underlying tooling that relies on synchronous calls. Once I migrate everything to use asynchronous API I can confirm whether this works as reliably as expected. |
I have deployed this branch to multichain0.testnet and I can confirm that it works as expected. You can try it out for yourself by calling:
Example tx: https://testnet.nearblocks.io/txns/3wJaSDxNZMPuZkzords3eEK3PkcHMnhtffQWP2cPPET5#execution |
contract/src/lib.rs
Outdated
pub fn sign(&mut self, payload: [u8; 32], path: String) -> [u8; 32] { | ||
near_sdk::env::random_seed_array() | ||
pub fn sign(&mut self, payload: [u8; 32], path: String) -> Promise { | ||
self.pending_requests.insert(&payload, &None); |
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.
This allows two different accounts to submit the same payload simultaneously, but only one of the sign
calls will return successfully, and possibly with the wrong signature.
pending_requests
should either be keyed with the payload and the predecessor combined, or sign
should reject duplicate, simultaneous payloads.
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 besides the one thing @encody mentioned above
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
@ChaoticTempest I've fixed the conflict and prevented the submission of the same payload. Take a look and let's merge it.
Terraform Feature Environment Destroy (dev-401)Terraform Initialization ⚙️
|
Adding a prototype of what the self call approach described in near/NEPs#516 (comment) would look like:
sign
function recursively calls itself until it runs out of gasrespond
function can add the requested signatures and allowsign
to return the signatureTo test this implementation:
cargo build -p mpc-contract --target wasm32-unknown-unknown --release
nearup run localnet --num-shards 1 --binary-path <path-for-nearcore-binary>
mpc.node0
below)env NEAR_ENV=localnet near deploy mpc.node0 <path-to-contract-wasm> init '{"threshold": 1, "participants":{}}' --keyPath ~/.near-credentials/localnet/mpc.node0.json
env NEAR_ENV=localnet near call mpc.node0 sign '{"payload":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}' --accountId mpc.node0 --keyPath ~/.near-credentials/localnet/mpc.node0.json --gas 300000000000000
Observe that it eventually returns a "exceeded prepaid gas" error after recursing 52 times.
Now to see that
respond
works. We can submit a signature byif there is a
sign
call running at the same time, it will terminate and returnsomething
.