Skip to content

Adding block height on tx#443

Closed
igormcoelho wants to merge 6 commits intoneo-project:masterfrom
igormcoelho:add_block_height_on_tx
Closed

Adding block height on tx#443
igormcoelho wants to merge 6 commits intoneo-project:masterfrom
igormcoelho:add_block_height_on_tx

Conversation

@igormcoelho
Copy link
Copy Markdown
Contributor

This is an implementation for #414. The idea is to include the top block height on tx, so it's easy to track old transactions. I included Block Hash (UInt256), instead of Block Height, because block height can be easily frauded, but hash cannot.

@ThomasLobker
Copy link
Copy Markdown

Should there be a setting that defines how stale a transaction may be? And should the staleness be used for mempool sorting?

@igormcoelho
Copy link
Copy Markdown
Contributor Author

Right now, my intention is just to include the height on tx, as Erik proposed. After that, we can see what we can do with that... a lot of good things I hope :)

@igormcoelho
Copy link
Copy Markdown
Contributor Author

Perhaps this is too expensive (extra 32B), so if community disagrees with the idea we can simply ignore this PR :)

@jsolman
Copy link
Copy Markdown
Contributor

jsolman commented Nov 4, 2018

We could include the block number as well as the first 8 bytes of the hash. That would be less bytes but still sufficient for the purpose this is needed. The number can be verified then by the first 8 bytes of the hash needing to match the block specified.

@shargon
Copy link
Copy Markdown
Member

shargon commented Nov 6, 2018

We need to know.. why we need this field, because the people could fake it, and say, my tx is waiting for 2 hours, should be dropped? should be prioritized? both cases are wrong for me, i preffer tonuse the reception time like now does

@jsolman
Copy link
Copy Markdown
Contributor

jsolman commented Nov 6, 2018

@shargon you can’t fake it if you have to put part of the blockhash and the block number in an attribute or something like that when signing the transaction.

@ThomasLobker
Copy link
Copy Markdown

ThomasLobker commented Nov 6, 2018

We could include the block number as well as the first 8 bytes of the hash.

What does the blockheight add for information? The hash is already indexed and has all the information about the block that you would want (including the height). If you add the blockhash of a recently created block, then you have proof that the transaction is also recently created. Eventually NEO can start discarding stale transactions.

I don't think it's worth while to truncate the hash to the first 8 bytes. It's probably more efficient to just include and compare the whole hash.

@jsolman
Copy link
Copy Markdown
Contributor

jsolman commented Nov 6, 2018

@ThomasLobker it is not more efficient to compare the whole hash, and it is less expensive to compare the hash if you know the block number.

The block number is needed to support using less bytes of the hash.

@shargon
Copy link
Copy Markdown
Member

shargon commented Nov 7, 2018

@jsolman if create a TX with the hash of the current height minus 100, what should be the procedure?
A- is waiting 100 blocks, so it should be prioritized because is more spread around the network
B- should be dropped because is waiting to much

If you prioritize new TX instead of old transactions, the spread should be slowly and could be problematic, i don't like this proposal to much

@igormcoelho
Copy link
Copy Markdown
Contributor Author

igormcoelho commented Nov 8, 2018

@jsolman I like your solution, 4 bytes on block + 8 bytes on hash (or perhaps less? 4 + 4 bytes is enough? 1/ billion chance).

@shargon I see your point my friend, and I agree that priority should not be given to newest, but to the oldest. This is exactly like an optimization problem with an unbounded variable... if unbounded goes in optimization direction, there's no solution. But if it goes otherwise.. no problem :)
Meaning that, we want to maximize block height, so incentive must go in this direction. How? We can cut the transactions older than an specific value. So, we don't use for sorting, but just to ensure that no transaction will live forever. How much will it live, we can discuss.. 1 day? 1 week? We can calculate.
Thing is, from user perspective, I don't see an advantage to let transactions live more than 1 minute. Independently of this PR, we already have this script done, to attach on transactions and let its live be short (users will also be able to configure expiration time on wallet):

The problem is, even with these scripts, I cannot guarantee that nodes will actually drop the transactions after time has passed (I only know they won't pass verify anymore), so mempool can become filled with non-executing transactions (as recently discussed with @snowypowers). Adding block height is one of the fewest things that can actually guarantee that no transaction will live forever, on any relay node.

@jsolman
Copy link
Copy Markdown
Contributor

jsolman commented Nov 20, 2018

@shargon It seems better to weight old transactions more heavily as they get older.

They are accepted if their weight gets large enough to be accepted before they become so old they drop off. This might mean that a free transaction waiting for quite some time may eventually have more weight than a new transaction that had a very small fee applied, but the one with the fee applied would also have its weight increased as it waits.

@shargon
Copy link
Copy Markdown
Member

shargon commented Nov 22, 2018

We can do that without add this hashes, and is fakeable, if you weight old transactions, i ever can send mine TX with Height-200
Now we attach the receptionDate to the TX, this value is confiable, and we should use this for any propuse

@jsolman
Copy link
Copy Markdown
Contributor

jsolman commented Nov 22, 2018

@shargon that is a good point about faking being older. Adding reception date could probably still have problems actually, because a node can’t only rely on its own reception date; it could have just restarted and still needs to accept transactions that were first sent a while in the past.

I think it is better to just make the code be able to handle the full mempool situation better and not try to expire by age. If a transaction wants to ensure it expires by age adding a script to make it invalid is enough.

@jsolman
Copy link
Copy Markdown
Contributor

jsolman commented Dec 5, 2018

I think this will be unnecessary after the mempool changes.

@igormcoelho
Copy link
Copy Markdown
Contributor Author

Well done.

@igormcoelho igormcoelho closed this Dec 6, 2018
Thacryba pushed a commit to simplitech/neo that referenced this pull request Feb 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants