2

I am trying to determine what data type to use for indexing transaction logs.

At least in the case of transactions per block, there is a hard limit.

Is it a fixed number and is there a maximum number?

2
  • How does the data type you use for indexing logs relate to the maximum logs possible per transaction?
    – dwardu
    May 29, 2021 at 18:28
  • 1
    I need to know if log index can fit into small int. For what is is worth, based on everything I've read so far, I am pretty confident it will always do.
    – Gajus
    May 29, 2021 at 18:29

2 Answers 2

2

There's no hard limit on LOG entries. In practice it is limited by the block gas limit and the cost of each LOG opcode.

Currently the minimum cost for a LOG is 375 (reference: https://github.com/wolflo/evm-opcodes/blob/main/gas.md#a8-log-operations). In mainnet the block gas limit is 15M. So a program can generate up to 15*10^6 / 375 = 40000 log entries.

4
  • That's theoretical limit. Is it possible to hit that number in practice?
    – Gajus
    May 30, 2021 at 6:26
  • @Gajus There's no limit in theory. In practice you need to pushes 0 twice and a log0, total cost 375 + 3 + 3. For mainnet you can execute 39370.
    – Ismael
    May 30, 2021 at 7:27
  • In this case it’s simpler to calculate the theoretical limit than the “practical” one. Since the absolute limit is the theoretical one, better to work with that. You’re in luck because log2(15 * 10^6 / 375) = 15.29, so you’re covered with a uint16 (in whichever language you’re using.) But who knows, the block limit could go up, and the cost of a log0 could go up, so to be “safe” I’d go for a uint32 and then forget about it forever.
    – dwardu
    May 30, 2021 at 18:34
  • If you want a practical limit, you can’t really calculate it, but you can estimate it empirically. E.g. if you take the last couple of blocks, count the logs per block and plot the histogram of this count, you will get a pretty good idea.
    – dwardu
    May 30, 2021 at 18:39
2

Ismael has added a good answer for your main question, so partial answer for the part about transactions per block:

The hard limit you've referred to is for Bitcoin, and it's a few years out of date.

For Ethereum, the two things to consider are:

  • The current block gas limit, which is 15 Mgas
  • The base gas cost of an EOA -> EOA transaction (i.e. 21,000 gas)

Taking these into account, the current tx/block limit is ~714 transactions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.