github.com/amazechain/amc@v0.1.3/modules/table.go (about) 1 // Copyright 2023 The AmazeChain Authors 2 // This file is part of the AmazeChain library. 3 // 4 // The AmazeChain library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The AmazeChain library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the AmazeChain library. If not, see <http://www.gnu.org/licenses/>. 16 17 package modules 18 19 import ( 20 "sort" 21 "strings" 22 23 "github.com/ledgerwatch/erigon-lib/kv" 24 ) 25 26 //const PlainState = "PlainState" 27 28 // StateInfo 29 const ( 30 // DatabaseInfo is used to store information about data layout. 31 DatabaseInfo = "DbInfo" 32 ChainConfig = "ChainConfig" 33 ) 34 35 // PlainState 36 const ( 37 //key - contract code hash 38 //value - contract code 39 Code = "Code" // contract code hash -> contract code 40 Account = "Account" // address(un hashed) -> account encoded 41 Storage = "Storage" // address (un hashed) + incarnation + storage key (un hashed) -> storage value(types.Hash) 42 Reward = "Reward" // ... 43 Deposit = "Deposit" // Deposit info 44 45 //key - addressHash+incarnation 46 //value - code hash 47 ContractCode = "HashedCodeHash" 48 49 PlainContractCode = "PlainCodeHash" // address+incarnation -> code hash 50 51 // IncarnationMap "incarnation" - uint16 number - how much times given account was SelfDestruct'ed 52 IncarnationMap = "IncarnationMap" // address -> incarnation of account when it was last deleted 53 ) 54 55 // HistoryState 56 const ( 57 AccountChangeSet = "AccountChangeSet" // blockNum_u64 -> address + account(encoded) 58 AccountsHistory = "AccountHistory" // address + shard_id_u64 -> roaring bitmap - list of block where it changed 59 60 StorageChangeSet = "StorageChangeSet" // blockNum_u64 + address + incarnation_u64 -> plain_storage_key + value 61 StorageHistory = "StorageHistory" // address + storage_key + shard_id_u64 -> roaring bitmap - list of block where it changed 62 ) 63 64 // Block 65 const ( 66 Headers = "Header" // block_num_u64 + hash -> header 67 HeaderNumber = "HeaderNumber" // header_hash -> num_u64 68 HeaderTD = "HeadersTotalDifficulty" // block_num_u64 + hash -> td 69 HeaderCanonical = "CanonicalHeader" // block_num_u64 -> header hash 70 71 // headBlockKey tracks the latest know full block's hash. 72 HeadBlockKey = "LastBlock" 73 74 HeadHeaderKey = "LastHeader" 75 76 BlockBody = "BlockBody" // block_num_u64 + hash -> block body 77 BlockTx = "BlockTransaction" // tbl_sequence_u64 -> (tx) 78 NonCanonicalTxs = "NonCanonicalTransaction" // tbl_sequence_u64 -> rlp(tx) 79 MaxTxNum = "MaxTxNum" // block_number_u64 -> max_tx_num_in_block_u64 80 TxLookup = "BlockTransactionLookup" // hash -> transaction/receipt lookup metadata 81 82 BlockVerify = "BlockVerify" 83 BlockRewards = "BlockRewards" 84 85 // Transaction senders - stored separately from the block bodies 86 Senders = "TxSender" // block_num_u64 + blockHash -> sendersList (no serialization format, every 20 bytes is new sender) 87 88 Receipts = "Receipt" // block_num_u64 -> canonical block receipts (non-canonical are not stored) 89 Log = "TransactionLog" // block_num_u64 + txId -> logs of transaction 90 91 // Stores bitmap indices - in which block numbers saw logs of given 'address' or 'topic' 92 // [addr or topic] + [2 bytes inverted shard number] -> bitmap(blockN) 93 // indices are sharded - because some bitmaps are >1Mb and when new incoming blocks process it 94 // updates ~300 of bitmaps - by append small amount new values. It cause much big writes (MDBX does copy-on-write). 95 // 96 // if last existing shard size merge it with delta 97 // if serialized size of delta > ShardLimit - break down to multiple shards 98 // shard number - it's biggest value in bitmap 99 LogTopicIndex = "LogTopicIndex" 100 LogAddressIndex = "LogAddressIndex" 101 102 // CallTraceSet is the name of the table that contain the mapping of block number to the set (sorted) of all accounts 103 // touched by call traces. It is DupSort-ed table 104 // 8-byte BE block number -> account address -> two bits (one for "from", another for "to") 105 CallTraceSet = "CallTraceSet" 106 // Indices for call traces - have the same format as LogTopicIndex and LogAddressIndex 107 // Store bitmap indices - in which block number we saw calls from (CallFromIndex) or to (CallToIndex) some addresses 108 CallFromIndex = "CallFromIndex" 109 CallToIndex = "CallToIndex" 110 111 Sequence = "Sequence" // tbl_name -> seq_u64 112 113 Stake = "Stake" // stakes amc_stake -> bytes 114 115 ) 116 117 const ( 118 SignersDB = "signersDB" 119 PoaSnapshot = "poaSnapshot" 120 ) 121 122 var AmcTables = []string{ 123 Code, 124 Account, 125 Storage, 126 PlainContractCode, 127 IncarnationMap, 128 129 DatabaseInfo, 130 ChainConfig, 131 132 AccountsHistory, 133 AccountChangeSet, 134 StorageHistory, 135 StorageChangeSet, 136 137 Headers, 138 HeaderTD, 139 HeaderCanonical, 140 HeaderNumber, 141 142 HeadBlockKey, 143 HeadHeaderKey, 144 145 BlockBody, 146 BlockTx, 147 148 TxLookup, 149 Senders, 150 Receipts, 151 Log, 152 153 SignersDB, 154 PoaSnapshot, 155 Sequence, 156 157 Reward, 158 Deposit, 159 BlockVerify, 160 BlockRewards, 161 } 162 163 var AmcTableCfg = kv.TableCfg{ 164 AccountChangeSet: {Flags: kv.DupSort}, 165 StorageChangeSet: {Flags: kv.DupSort}, 166 Storage: { 167 Flags: kv.DupSort, 168 AutoDupSortKeysConversion: true, 169 DupFromLen: 54, 170 DupToLen: 34, 171 }, 172 } 173 174 func AmcInit() { 175 sort.SliceStable(AmcTables, func(i, j int) bool { 176 return strings.Compare(AmcTables[i], AmcTables[j]) < 0 177 }) 178 for _, name := range AmcTables { 179 _, ok := AmcTableCfg[name] 180 if !ok { 181 AmcTableCfg[name] = kv.TableCfgItem{} 182 } 183 } 184 }