ArcPay / arcpay-server

1 stars 0 forks source link

update state only after 100 seconds #27

Closed 0xbok closed 1 year ago

0xbok commented 1 year ago

turned out to be a simple implementation.

A constant MAX_SINCE_LAST_PROVE: u64 is set to 100 seconds. Whenever the server starts, it sets a variable last_finalize_time to 0. This is meant to track the timestamp of the last finalized transaction.

Initializing it to 0 is correct as this means the first user request will always lead to a mainnet transaction to finalize state.

On each user request, finalized state is updated if the gap between current time and last_finalize_time is greater than MAX_SINCE_LAST_PROVE; last_finalize_time is also updated to current time.

Note: Need to ensure that the contract doesn't slash the operator when there is no user request after the last finalized state. Operator only updates the state when there is a user request to send or mint.