warp-contracts / warp

An implementation of the Arweave SmartWeave smart contracts protocol.
MIT License
159 stars 44 forks source link

[FEATURE] Safe Block Fetch #464

Closed vilenarios closed 1 year ago

vilenarios commented 1 year ago

Is your feature request related to a problem? Please describe. The protocol we are trying to build in SmartWeave requires a source of entropy. We were planning on using the indep_hash from old blocks to accomplish this. Unfortunately, there is no way to get block information from any block other than the current block.

Describe the solution you'd like Adding the ability to get old block information via the SmartWeave global object i.e.

SmartWeave.arweave.safeBlockFetch(height: number)

Describe alternatives you've considered We also considered using unsafeClient, such as SmartWeave.unsafeClient.blocks.getByHeight(height: number) but this requires a change to our contract manifest, which we would like to avoid.

Additional context This is to support the upcoming ar.io network contract.

Arweave.js includes blocks.getByHeight(height; number) in August 2023.

ppedziwiatr commented 1 year ago

1.4.22-beta.1 Example in contract: https://github.com/warp-contracts/warp/pull/467/files#diff-7c2f2726dde97a0eac95e0a579992901ec061c79db74dba88989f1c62cf07f71R44

test: https://github.com/warp-contracts/warp/pull/467/files#diff-f8bb2d6c56677af3ad9d155f3f711d115ebd744848e85627693f8c4951066efaR155

Keep in mine (as the second test shows) that any error in communication will cause the evaluation to immiedietaly stop.

So if you make a mistake in the api address, etc - you will break your contract forever - unfortunatelly I'm unable to differentiate cases where - for example - 404 response code from api means some temporary issue with the api itself - from a case where a contract developer is imply using a wrong address.

ppedziwiatr commented 1 year ago

1.4.22-beta.2 - it now takes the arweave url (from the Arweave instance connected to warp) as a base url for requests - https://github.com/warp-contracts/warp/pull/468/files#diff-ac391c5c28b096d56ab2f53411b414da0dea20d2eb84191352881177d1c5dcecR44

dtfiedler commented 1 year ago

we're currently using this feature (1.4.22) and looks to work as expected!