hexresearch / hschain-utxo

UTXO-based contracts for hschain
0 stars 0 forks source link

We should have box input Value in the BoxInputRef #150

Closed thesz closed 4 years ago

thesz commented 4 years ago

We need them in

  1. Selecting transaction in a block and computing comissions - otherwise there will be series of queries to DB.
  2. Verifying transactions in a block - there will be series of queries to DB in either case, but we may check for commission faster if we have money sums ready.

We may check for correctness of money amount when fetching the box using BoxInputRef.

Shimuuar commented 4 years ago

Cons:

  1. One have to store store input refs forever.
  2. One more things to check. Not only we have to look up DB anyway but we have to check that transaction is consistent with what is written in DB.

RE 1: Transactions for block are selected from mempool and mempool checks transactions before accepting them anyway. So it could cache amount stored in inputs.

On this note. I played a bit with idea of writing transaction as:

data Tx i o = Tx
  { tx'inputs  :: !(Vector i)   -- ^ List of inputs
  , tx'outputs :: !(Vector o)           -- ^ List of outputs
  }

This way we can use Tx InputRef Box as on-wire transactions and keep Tx (Money,InputRef) Box in mempool.

thesz commented 4 years ago

We are fetching boxes using BoxInputRef for validation purposes. We can check amounts at that moment.

I completely agree with the Tx i o.