smartcontractkit / near-protocol-contracts

MIT License
26 stars 8 forks source link

Keep track of latest nonce per account, make nonces non-reusable #19

Closed krebernisak closed 4 years ago

krebernisak commented 4 years ago

We need to have some mechanism to filter requests that are in flight so we do not raise duplicate request events for the Chainlink node. As NEAR does not have events, or the API to fetch events from some block number onwards, as we use for Ethereum, we need a way to filter requests that were already raised but not yet fulfilled.

The idea is to keep track and not reuse nonces, per account. When storing new requests, the contract would check that the new nonce is larger than the one last seen, and store it in a map for the account.

The contract would then expose a get_nonces function that would return a map: HashMap<&str, u32>, that would map account => latest_nonce.

The initiator on the Chainlink side would use the API when it starts (or restarts after a crash), to get the latest state, and filter any requests that happened before that point in time.

The initiator also keeps track of the latest nonces for every request it sees, as it will poll the requests from the contracts every second or so, and needs to filter the ones it has already seen.

krebernisak commented 4 years ago

You can use Add NEAR request filter by seen nonce #10 PR as a reference.