JacobCairncross / Kebab

0 stars 0 forks source link

Check for double spend #1

Open JacobCairncross opened 1 month ago

JacobCairncross commented 1 month ago

Need to check if a transaction output has been used before allowing it to be used as a transaction input.

Can do this by maintaining an index of all unspent transactions to make checking speedier.

Would be best to implement entity framework properly before doing this so we can store stuff better than just in the object (make sure to have an option to clear the db on start up though for easier testing)

JacobCairncross commented 1 month ago

Been deciding how to minimise the lifetime of the db but having the lifetime be for the whole request should be fine https://learn.microsoft.com/en-us/ef/ef6/fundamentals/working-with-dbcontext#lifetime so you can just inject it into the constructor of where its needed

JacobCairncross commented 1 month ago

need to rework the dependancy injection to ensure I dont put the db context into a singleton. It may be best to make everything scoped and then build the chain up from the DB each time its needed. This seems like it'll be slow but it might be fine. Also think how this works when we switch to doing a block of multiple requests and not just a block per request. Better yet, rework the blockchain class so it doesnt build up, it just accesses the db for you.

JacobCairncross commented 3 days ago

Maybe actually reading a bit of documentation might help https://learn.microsoft.com/en-us/ef/core/modeling/relationships/one-to-many

JacobCairncross commented 3 days ago

DB is set up for the genesis transaction. Need to ensure it works for transactions afterwards, then focus on double spend