geniusyield / atlas

Application backend for Plutus smart contracts on Cardano
https://atlas-app.io
Apache License 2.0
67 stars 18 forks source link

`someUTxO` does not actually update `envUsedSomeUTxOs` in `GYTxMonadNode` #318

Open TotallyNotChase opened 4 months ago

TotallyNotChase commented 4 months ago

Describe the bug If we look at the current someUTxO implementation for GYTxMonadNode:

someUTxO lang = do
    addrs           <- ownAddresses
    utxosToConsider <- availableUTxOs
    case lang of
      PlutusV2 ->
        case someTxOutRef utxosToConsider  of
            Just (oref, _) -> return oref
            Nothing        -> throwError . GYQueryUTxOException $ GYNoUtxosAtAddress addrs
      PlutusV1 ->
        case find utxoTranslatableToV1 $ utxosToList utxosToConsider of
          Just u  -> return $ utxoRef u
          Nothing -> throwError . GYQueryUTxOException $ GYNoUtxosAtAddress addrs  -- TODO: Better error message here?

We notice that the returned UTxO isn't actually removed from envUsedSomeUTxO. This seems problematic since the point of envUsedSomeUTxO is to track previously yielded someUTxOs so they aren't returned repeatedly.

As it currently stands, the field envUsedSomeUTxO is actually useless.

Expected behavior

envUsedSomeUTxO should be updated accordingly.

Additional context

Has this always been like this? I thought it used to work.

TotallyNotChase commented 4 months ago

Tangentially related but the framework should use availableUTxOs wherever possible to obtain own utxos, instead of querying the own addresses.

TotallyNotChase commented 4 months ago

Also, someUTxO impl for GYTxMonadNode should really be replaced with the randomTxOutRef from GYUTxO

sourabhxyz commented 4 months ago

As it currently stands, the field envUsedSomeUTxO is actually useless.

That is true, I think it never served any meaningful purpose and was just there in case we wanted to give it some meaning.

We notice that the returned UTxO isn't actually removed from envUsedSomeUTxO. This seems problematic since the point of envUsedSomeUTxO is to track previously yielded someUTxOs so they aren't returned repeatedly.

I think you meant that it is not added to envUsedSomeUTxOs?