diff --git a/builder/files/genesis-testnet-v4.json b/builder/files/genesis-testnet-v4.json index 34407a391a..c848d5dce0 100644 --- a/builder/files/genesis-testnet-v4.json +++ b/builder/files/genesis-testnet-v4.json @@ -13,6 +13,7 @@ "muirGlacierBlock": 2722000, "berlinBlock": 13996000, "londonBlock": 22640000, + "shanghaiBlock": 41874000, "bor": { "jaipurBlock": 22770000, "delhiBlock": 29638656, @@ -42,7 +43,8 @@ "validatorContract": "0x0000000000000000000000000000000000001000", "stateReceiverContract": "0x0000000000000000000000000000000000001001", "burntContract": { - "22640000": "0x70bcA57F4579f58670aB2d18Ef16e02C17553C38" + "22640000": "0x70bcA57F4579f58670aB2d18Ef16e02C17553C38", + "41874000": "0x617b94CCCC2511808A3C9478ebb96f455CF167aA" }, "blockAlloc": { "22244000": { @@ -50,6 +52,12 @@ "balance": "0x0", "code": "0x60806040526004361061019c5760003560e01c806377d32e94116100ec578063acd06cb31161008a578063e306f77911610064578063e306f77914610a7b578063e614d0d614610aa6578063f2fde38b14610ad1578063fc0c546a14610b225761019c565b8063acd06cb31461097a578063b789543c146109cd578063cc79f97b14610a505761019c565b80639025e64c116100c65780639025e64c146107c957806395d89b4114610859578063a9059cbb146108e9578063abceeba21461094f5761019c565b806377d32e94146106315780638da5cb5b146107435780638f32d59b1461079a5761019c565b806347e7ef24116101595780637019d41a116101335780637019d41a1461053357806370a082311461058a578063715018a6146105ef578063771282f6146106065761019c565b806347e7ef2414610410578063485cc9551461046b57806360f96a8f146104dc5761019c565b806306fdde03146101a15780631499c5921461023157806318160ddd1461028257806319d27d9c146102ad5780632e1a7d4d146103b1578063313ce567146103df575b600080fd5b3480156101ad57600080fd5b506101b6610b79565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101f65780820151818401526020810190506101db565b50505050905090810190601f1680156102235780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561023d57600080fd5b506102806004803603602081101561025457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610bb6565b005b34801561028e57600080fd5b50610297610c24565b6040518082815260200191505060405180910390f35b3480156102b957600080fd5b5061036f600480360360a08110156102d057600080fd5b81019080803590602001906401000000008111156102ed57600080fd5b8201836020820111156102ff57600080fd5b8035906020019184600183028401116401000000008311171561032157600080fd5b9091929391929390803590602001909291908035906020019092919080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610c3a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6103dd600480360360208110156103c757600080fd5b8101908080359060200190929190505050610caa565b005b3480156103eb57600080fd5b506103f4610dfc565b604051808260ff1660ff16815260200191505060405180910390f35b34801561041c57600080fd5b506104696004803603604081101561043357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610e05565b005b34801561047757600080fd5b506104da6004803603604081101561048e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610fc1565b005b3480156104e857600080fd5b506104f1611090565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561053f57600080fd5b506105486110b6565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561059657600080fd5b506105d9600480360360208110156105ad57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506110dc565b6040518082815260200191505060405180910390f35b3480156105fb57600080fd5b506106046110fd565b005b34801561061257600080fd5b5061061b6111cd565b6040518082815260200191505060405180910390f35b34801561063d57600080fd5b506107016004803603604081101561065457600080fd5b81019080803590602001909291908035906020019064010000000081111561067b57600080fd5b82018360208201111561068d57600080fd5b803590602001918460018302840111640100000000831117156106af57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506111d3565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561074f57600080fd5b50610758611358565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156107a657600080fd5b506107af611381565b604051808215151515815260200191505060405180910390f35b3480156107d557600080fd5b506107de6113d8565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561081e578082015181840152602081019050610803565b50505050905090810190601f16801561084b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561086557600080fd5b5061086e611411565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156108ae578082015181840152602081019050610893565b50505050905090810190601f1680156108db5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610935600480360360408110156108ff57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061144e565b604051808215151515815260200191505060405180910390f35b34801561095b57600080fd5b50610964611474565b6040518082815260200191505060405180910390f35b34801561098657600080fd5b506109b36004803603602081101561099d57600080fd5b8101908080359060200190929190505050611501565b604051808215151515815260200191505060405180910390f35b3480156109d957600080fd5b50610a3a600480360360808110156109f057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291908035906020019092919080359060200190929190505050611521565b6040518082815260200191505060405180910390f35b348015610a5c57600080fd5b50610a65611541565b6040518082815260200191505060405180910390f35b348015610a8757600080fd5b50610a90611548565b6040518082815260200191505060405180910390f35b348015610ab257600080fd5b50610abb61154e565b6040518082815260200191505060405180910390f35b348015610add57600080fd5b50610b2060048036036020811015610af457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506115db565b005b348015610b2e57600080fd5b50610b376115f8565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b60606040518060400160405280600b81526020017f4d6174696320546f6b656e000000000000000000000000000000000000000000815250905090565b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260108152602001807f44697361626c656420666561747572650000000000000000000000000000000081525060200191505060405180910390fd5b6000601260ff16600a0a6402540be40002905090565b60006040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260108152602001807f44697361626c656420666561747572650000000000000000000000000000000081525060200191505060405180910390fd5b60003390506000610cba826110dc565b9050610cd18360065461161e90919063ffffffff16565b600681905550600083118015610ce657508234145b610d58576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f496e73756666696369656e7420616d6f756e740000000000000000000000000081525060200191505060405180910390fd5b8173ffffffffffffffffffffffffffffffffffffffff16600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167febff2602b3f468259e1e99f613fed6691f3a6526effe6ef3e768ba7ae7a36c4f8584610dd4876110dc565b60405180848152602001838152602001828152602001935050505060405180910390a3505050565b60006012905090565b610e0d611381565b610e1657600080fd5b600081118015610e535750600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b610ea8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180611da96023913960400191505060405180910390fd5b6000610eb3836110dc565b905060008390508073ffffffffffffffffffffffffffffffffffffffff166108fc849081150290604051600060405180830381858888f19350505050158015610f00573d6000803e3d6000fd5b50610f168360065461163e90919063ffffffff16565b6006819055508373ffffffffffffffffffffffffffffffffffffffff16600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f4e2ca0515ed1aef1395f66b5303bb5d6f1bf9d61a353fa53f73f8ac9973fa9f68585610f98896110dc565b60405180848152602001838152602001828152602001935050505060405180910390a350505050565b600760009054906101000a900460ff1615611027576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180611d866023913960400191505060405180910390fd5b6001600760006101000a81548160ff02191690831515021790555080600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555061108c8261165d565b5050565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008173ffffffffffffffffffffffffffffffffffffffff16319050919050565b611105611381565b61110e57600080fd5b600073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60065481565b60008060008060418551146111ee5760009350505050611352565b602085015192506040850151915060ff6041860151169050601b8160ff16101561121957601b810190505b601b8160ff16141580156112315750601c8160ff1614155b156112425760009350505050611352565b60018682858560405160008152602001604052604051808581526020018460ff1660ff1681526020018381526020018281526020019450505050506020604051602081039080840390855afa15801561129f573d6000803e3d6000fd5b505050602060405103519350600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16141561134e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f4572726f7220696e2065637265636f766572000000000000000000000000000081525060200191505060405180910390fd5b5050505b92915050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614905090565b6040518060400160405280600381526020017f013881000000000000000000000000000000000000000000000000000000000081525081565b60606040518060400160405280600581526020017f4d41544943000000000000000000000000000000000000000000000000000000815250905090565b6000813414611460576000905061146e565b61146b338484611755565b90505b92915050565b6040518060800160405280605b8152602001611e1e605b91396040516020018082805190602001908083835b602083106114c357805182526020820191506020810190506020830392506114a0565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040516020818303038152906040528051906020012081565b60056020528060005260406000206000915054906101000a900460ff1681565b600061153761153286868686611b12565b611be8565b9050949350505050565b6201388181565b60015481565b604051806080016040528060528152602001611dcc605291396040516020018082805190602001908083835b6020831061159d578051825260208201915060208101905060208303925061157a565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040516020818303038152906040528051906020012081565b6115e3611381565b6115ec57600080fd5b6115f58161165d565b50565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008282111561162d57600080fd5b600082840390508091505092915050565b60008082840190508381101561165357600080fd5b8091505092915050565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561169757600080fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000803073ffffffffffffffffffffffffffffffffffffffff166370a08231866040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b1580156117d557600080fd5b505afa1580156117e9573d6000803e3d6000fd5b505050506040513d60208110156117ff57600080fd5b8101908080519060200190929190505050905060003073ffffffffffffffffffffffffffffffffffffffff166370a08231866040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b15801561189157600080fd5b505afa1580156118a5573d6000803e3d6000fd5b505050506040513d60208110156118bb57600080fd5b810190808051906020019092919050505090506118d9868686611c32565b8473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff16600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fe6497e3ee548a3372136af2fcb0696db31fc6cf20260707645068bd3fe97f3c48786863073ffffffffffffffffffffffffffffffffffffffff166370a082318e6040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b1580156119e157600080fd5b505afa1580156119f5573d6000803e3d6000fd5b505050506040513d6020811015611a0b57600080fd5b81019080805190602001909291905050503073ffffffffffffffffffffffffffffffffffffffff166370a082318e6040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015611a9957600080fd5b505afa158015611aad573d6000803e3d6000fd5b505050506040513d6020811015611ac357600080fd5b8101908080519060200190929190505050604051808681526020018581526020018481526020018381526020018281526020019550505050505060405180910390a46001925050509392505050565b6000806040518060800160405280605b8152602001611e1e605b91396040516020018082805190602001908083835b60208310611b645780518252602082019150602081019050602083039250611b41565b6001836020036101000a03801982511681845116808217855250505050505090500191505060405160208183030381529060405280519060200120905060405181815273ffffffffffffffffffffffffffffffffffffffff8716602082015285604082015284606082015283608082015260a0812092505081915050949350505050565b60008060015490506040517f190100000000000000000000000000000000000000000000000000000000000081528160028201528360228201526042812092505081915050919050565b3073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611cd4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f63616e27742073656e6420746f204d524332300000000000000000000000000081525060200191505060405180910390fd5b8173ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f19350505050158015611d1a573d6000803e3d6000fd5b508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a350505056fe54686520636f6e747261637420697320616c726561647920696e697469616c697a6564496e73756666696369656e7420616d6f756e74206f7220696e76616c69642075736572454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c75696e7432353620636861696e49642c6164647265737320766572696679696e67436f6e747261637429546f6b656e5472616e736665724f726465722861646472657373207370656e6465722c75696e7432353620746f6b656e49644f72416d6f756e742c6279746573333220646174612c75696e743235362065787069726174696f6e29a265627a7a72315820ccd6c2a9c259832bbb367986ee06cd87af23022681b0cb22311a864b701d939564736f6c63430005100032" } + }, + "41874000": { + "0x0000000000000000000000000000000000001001": { + "balance": "0x0", + "code": "0x608060405234801561001057600080fd5b506004361061005e576000357c01000000000000000000000000000000000000000000000000000000009004806319494a17146100635780633434735f146100fe5780635407ca6714610148575b600080fd5b6100e46004803603604081101561007957600080fd5b8101908080359060200190929190803590602001906401000000008111156100a057600080fd5b8201836020820111156100b257600080fd5b803590602001918460018302840111640100000000831117156100d457600080fd5b9091929391929390505050610166565b604051808215151515815260200191505060405180910390f35b6101066104d3565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6101506104eb565b6040518082815260200191505060405180910390f35b600073fffffffffffffffffffffffffffffffffffffffe73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461021d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f4e6f742053797374656d2041646465737321000000000000000000000000000081525060200191505060405180910390fd5b606061027461026f85858080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050506104f1565b61051f565b905060006102958260008151811061028857fe5b60200260200101516105fc565b90508060016000540114610311576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f537461746549647320617265206e6f742073657175656e7469616c000000000081525060200191505060405180910390fd5b600080815480929190600101919050555060006103418360018151811061033457fe5b602002602001015161066d565b905060606103628460028151811061035557fe5b6020026020010151610690565b905061036d8261071c565b156104c8576000624c4b409050606084836040516024018083815260200180602001828103825283818151815260200191508051906020019080838360005b838110156103c75780820151818401526020810190506103ac565b50505050905090810190601f1680156103f45780820380516001836020036101000a031916815260200191505b5093505050506040516020818303038152906040527f26c53bea000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050905060008082516020840160008887f19650847f5a22725590b0a51c923940223f7458512164b1113359a735e86e7f27f44791ee88604051808215151515815260200191505060405180910390a250505b505050509392505050565b73fffffffffffffffffffffffffffffffffffffffe81565b60005481565b6104f961099c565b600060208301905060405180604001604052808451815260200182815250915050919050565b606061052a82610735565b61053357600080fd5b600061053e83610783565b905060608160405190808252806020026020018201604052801561057c57816020015b6105696109b6565b8152602001906001900390816105615790505b509050600061058e85602001516107f4565b8560200151019050600080600090505b848110156105ef576105af8361087d565b91506040518060400160405280838152602001848152508482815181106105d257fe5b60200260200101819052508183019250808060010191505061059e565b5082945050505050919050565b600080826000015111801561061657506021826000015111155b61061f57600080fd5b600061062e83602001516107f4565b9050600081846000015103905060008083866020015101905080519150602083101561066157826020036101000a820491505b81945050505050919050565b6000601582600001511461068057600080fd5b610689826105fc565b9050919050565b606060008260000151116106a357600080fd5b60006106b283602001516107f4565b905060008184600001510390506060816040519080825280601f01601f1916602001820160405280156106f45781602001600182028038833980820191505090505b5090506000816020019050610710848760200151018285610935565b81945050505050919050565b600080823b905060008163ffffffff1611915050919050565b6000808260000151141561074c576000905061077e565b60008083602001519050805160001a915060c060ff168260ff1610156107775760009250505061077e565b6001925050505b919050565b6000808260000151141561079a57600090506107ef565b600080905060006107ae84602001516107f4565b84602001510190506000846000015185602001510190505b808210156107e8576107d78261087d565b8201915082806001019350506107c6565b8293505050505b919050565b600080825160001a9050608060ff16811015610814576000915050610878565b60b860ff16811080610839575060c060ff168110158015610838575060f860ff1681105b5b15610848576001915050610878565b60c060ff168110156108685760018060b80360ff16820301915050610878565b60018060f80360ff168203019150505b919050565b6000806000835160001a9050608060ff1681101561089e576001915061092b565b60b860ff168110156108bb576001608060ff16820301915061092a565b60c060ff168110156108eb5760b78103600185019450806020036101000a85510460018201810193505050610929565b60f860ff1681101561090857600160c060ff168203019150610928565b60f78103600185019450806020036101000a855104600182018101935050505b5b5b5b8192505050919050565b600081141561094357610997565b5b602060ff1681106109735782518252602060ff1683019250602060ff1682019150602060ff1681039050610944565b6000600182602060ff16036101000a03905080198451168184511681811785525050505b505050565b604051806040016040528060008152602001600081525090565b60405180604001604052806000815260200160008152509056fea265627a7a723158208f1ea6fcf63d6911ac5dbfe340be1029614581802c6a750e7d6354b32ce6647c64736f6c63430005110032" + } } } } diff --git a/cmd/evm/internal/t8ntool/transaction.go b/cmd/evm/internal/t8ntool/transaction.go index 02e9db1bf6..edce0aca8f 100644 --- a/cmd/evm/internal/t8ntool/transaction.go +++ b/cmd/evm/internal/t8ntool/transaction.go @@ -157,7 +157,7 @@ func Transaction(ctx *cli.Context) error { } // Check intrinsic gas if gas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil, - chainConfig.IsHomestead(new(big.Int)), chainConfig.IsIstanbul(new(big.Int)), chainConfig.IsShanghai(0)); err != nil { + chainConfig.IsHomestead(new(big.Int)), chainConfig.IsIstanbul(new(big.Int)), chainConfig.IsShanghai(new(big.Int))); err != nil { r.Error = err results = append(results, r) @@ -190,9 +190,8 @@ func Transaction(ctx *cli.Context) error { case new(big.Int).Mul(tx.GasFeeCap(), new(big.Int).SetUint64(tx.Gas())).BitLen() > 256: r.Error = errors.New("gas * maxFeePerGas exceeds 256 bits") } - // TODO marcello double check // Check whether the init code size has been exceeded. - if chainConfig.IsShanghai(0) && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize { + if chainConfig.IsShanghai(new(big.Int)) && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize { r.Error = errors.New("max initcode size exceeded") } diff --git a/cmd/evm/internal/t8ntool/transition.go b/cmd/evm/internal/t8ntool/transition.go index 952b30f08a..165c842baa 100644 --- a/cmd/evm/internal/t8ntool/transition.go +++ b/cmd/evm/internal/t8ntool/transition.go @@ -285,8 +285,8 @@ func Transition(ctx *cli.Context) error { return NewError(ErrorConfig, errors.New("EIP-1559 config but missing 'currentBaseFee' in env section")) } } - // TODO marcello double check - if chainConfig.IsShanghai(prestate.Env.Number) && prestate.Env.Withdrawals == nil { + + if chainConfig.IsShanghai(big.NewInt(int64(prestate.Env.Number))) && prestate.Env.Withdrawals == nil { return NewError(ErrorConfig, errors.New("Shanghai config but missing 'withdrawals' in env section")) } diff --git a/cmd/evm/t8n_test.go b/cmd/evm/t8n_test.go index cbe2926206..e98651ae28 100644 --- a/cmd/evm/t8n_test.go +++ b/cmd/evm/t8n_test.go @@ -238,7 +238,6 @@ func TestT8n(t *testing.T) { output: t8nOutput{result: true}, expOut: "exp.json", }, - // TODO marcello double check { // Test post-merge transition base: "./testdata/24", input: t8nInput{ diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 5e2cf95642..8221ae69c2 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -18,6 +18,7 @@ package main import ( "fmt" + "math/big" "os" "time" @@ -147,10 +148,9 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) { // makeFullNode loads geth configuration and creates the Ethereum backend. func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { stack, cfg := makeConfigNode(ctx) - // TODO marcello double check if ctx.IsSet(utils.OverrideShanghai.Name) { - v := ctx.Uint64(utils.OverrideShanghai.Name) - cfg.Eth.OverrideShanghai = &v + v := ctx.Int64(utils.OverrideShanghai.Name) + cfg.Eth.OverrideShanghai = new(big.Int).SetInt64(v) } backend, eth := utils.RegisterEthService(stack, &cfg.Eth) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 79aacbe3e8..05f5255c21 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -70,7 +70,6 @@ var ( utils.NoUSBFlag, utils.USBFlag, utils.SmartCardDaemonPathFlag, - // TODO marcello double check utils.OverrideShanghai, utils.EnablePersonal, utils.EthashCacheDirFlag, diff --git a/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index dd09723800..434f54b33b 100644 --- a/consensus/beacon/consensus.go +++ b/consensus/beacon/consensus.go @@ -283,8 +283,7 @@ func (beacon *Beacon) verifyHeader(chain consensus.ChainHeaderReader, header, pa return err } // Verify existence / non-existence of withdrawalsHash. - // TODO marcello double check - shanghai := chain.Config().IsShanghai(header.Time) + shanghai := chain.Config().IsShanghai(header.Number) if shanghai && header.WithdrawalsHash == nil { return errors.New("missing withdrawalsHash") } @@ -293,7 +292,7 @@ func (beacon *Beacon) verifyHeader(chain consensus.ChainHeaderReader, header, pa return fmt.Errorf("invalid withdrawalsHash: have %x, expected nil", header.WithdrawalsHash) } // Verify the existence / non-existence of excessDataGas - cancun := chain.Config().IsCancun(header.Time) + cancun := chain.Config().IsCancun(header.Number) if cancun && header.ExcessDataGas == nil { return errors.New("missing excessDataGas") } @@ -391,8 +390,8 @@ func (beacon *Beacon) FinalizeAndAssemble(ctx context.Context, chain consensus.C if !beacon.IsPoSHeader(header) { return beacon.ethone.FinalizeAndAssemble(ctx, chain, header, state, txs, uncles, receipts, nil) } - // TODO marcello double check - shanghai := chain.Config().IsShanghai(header.Time) + + shanghai := chain.Config().IsShanghai(header.Number) if shanghai { // All blocks after Shanghai must include a withdrawals root. if withdrawals == nil { diff --git a/consensus/bor/bor.go b/consensus/bor/bor.go index 1874e44d74..e4880f7914 100644 --- a/consensus/bor/bor.go +++ b/consensus/bor/bor.go @@ -381,11 +381,14 @@ func (c *Bor) verifyHeader(chain consensus.ChainHeaderReader, header *types.Head // Verify that the gas limit is <= 2^63-1 gasCap := uint64(0x7fffffffffffffff) - if header.GasLimit > gasCap { return fmt.Errorf("invalid gasLimit: have %v, max %v", header.GasLimit, gasCap) } + if header.WithdrawalsHash != nil { + return consensus.ErrUnexpectedWithdrawals + } + // All basic checks passed, verify cascading fields return c.verifyCascadingFields(chain, header, parents) } @@ -816,6 +819,10 @@ func (c *Bor) Finalize(chain consensus.ChainHeaderReader, header *types.Header, headerNumber := header.Number.Uint64() + if withdrawals != nil || header.WithdrawalsHash != nil { + return + } + if IsSprintStart(headerNumber, c.config.CalculateSprint(headerNumber)) { ctx := context.Background() cx := statefull.ChainContext{Chain: chain, Bor: c} @@ -888,10 +895,14 @@ func (c *Bor) FinalizeAndAssemble(ctx context.Context, chain consensus.ChainHead finalizeCtx, finalizeSpan := tracing.StartSpan(ctx, "bor.FinalizeAndAssemble") defer tracing.EndSpan(finalizeSpan) - stateSyncData := []*types.StateSyncData{} - headerNumber := header.Number.Uint64() + if withdrawals != nil || header.WithdrawalsHash != nil { + return nil, consensus.ErrUnexpectedWithdrawals + } + + stateSyncData := []*types.StateSyncData{} + var err error if IsSprintStart(headerNumber, c.config.CalculateSprint(headerNumber)) { diff --git a/consensus/bor/statefull/processor.go b/consensus/bor/statefull/processor.go index 039f3daae0..7f6d535989 100644 --- a/consensus/bor/statefull/processor.go +++ b/consensus/bor/statefull/processor.go @@ -1,6 +1,7 @@ package statefull import ( + "bytes" "context" "math" "math/big" @@ -90,7 +91,11 @@ func ApplyMessage( success := big.NewInt(5).SetBytes(ret) - if success.Cmp(big.NewInt(0)) == 0 { + validatorContract := common.HexToAddress(chainConfig.Bor.ValidatorContract) + + // if success == 0 and msg.To() != validatorContractAddress, log Error + // if msg.To() == validatorContractAddress, its committing a span and we don't get any return value + if success.Cmp(big.NewInt(0)) == 0 && !bytes.Equal(msg.To().Bytes(), validatorContract.Bytes()) { log.Error("message execution failed on contract", "msgData", msg.Data) } diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index 1db06e121c..6998a6d070 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -308,12 +308,12 @@ func (c *Clique) verifyHeader(chain consensus.ChainHeaderReader, header *types.H if header.GasLimit > params.MaxGasLimit { return fmt.Errorf("invalid gasLimit: have %v, max %v", header.GasLimit, params.MaxGasLimit) } - // TODO marcello double check - if chain.Config().IsShanghai(header.Time) { + + if chain.Config().IsShanghai(header.Number) { return fmt.Errorf("clique does not support shanghai fork") } - if chain.Config().IsCancun(header.Time) { + if chain.Config().IsCancun(header.Number) { return fmt.Errorf("clique does not support cancun fork") } // All basic checks passed, verify cascading fields diff --git a/consensus/errors.go b/consensus/errors.go index d508b6580f..e9dd977a1e 100644 --- a/consensus/errors.go +++ b/consensus/errors.go @@ -38,4 +38,7 @@ var ( // ErrInvalidTerminalBlock is returned if a block is invalid wrt. the terminal // total difficulty. ErrInvalidTerminalBlock = errors.New("invalid terminal block") + + // ErrUnexpectedWithdrawals is returned if a pre-Shanghai block has withdrawals. + ErrUnexpectedWithdrawals = errors.New("unexpected withdrawals") ) diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 3a1b65984a..2011a8da33 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -333,12 +333,12 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainHeaderReader, header, pa if diff := new(big.Int).Sub(header.Number, parent.Number); diff.Cmp(big.NewInt(1)) != 0 { return consensus.ErrInvalidNumber } - // TODO marcello double check - if chain.Config().IsShanghai(header.Time) { + + if chain.Config().IsShanghai(header.Number) { return fmt.Errorf("ethash does not support shanghai fork") } - if chain.Config().IsCancun(header.Time) { + if chain.Config().IsCancun(header.Number) { return fmt.Errorf("ethash does not support cancun fork") } // Verify the engine specific seal securing the block diff --git a/core/blockchain_test.go b/core/blockchain_test.go index 733c3faa38..7fbea1af52 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -4688,7 +4688,7 @@ func TestEIP3651(t *testing.T) { gspec.Config.LondonBlock = common.Big0 gspec.Config.TerminalTotalDifficulty = common.Big0 gspec.Config.TerminalTotalDifficultyPassed = true - gspec.Config.ShanghaiTime = u64(0) + gspec.Config.ShanghaiBlock = common.Big0 signer := types.LatestSigner(gspec.Config) _, blocks, _ := GenerateChainWithGenesis(gspec, engine, 1, func(i int, b *BlockGen) { diff --git a/core/chain_makers_test.go b/core/chain_makers_test.go index cdbe86cca6..5202c23f24 100644 --- a/core/chain_makers_test.go +++ b/core/chain_makers_test.go @@ -56,7 +56,7 @@ func TestGenerateWithdrawalChain(t *testing.T) { config.TerminalTotalDifficultyPassed = true config.TerminalTotalDifficulty = common.Big0 - config.ShanghaiTime = u64(0) + config.ShanghaiBlock = common.Big0 // init 0xaa with some storage elements storage := make(map[common.Hash]common.Hash) diff --git a/core/forkid/forkid_test.go b/core/forkid/forkid_test.go index 2c2fbb2910..4bd602b72b 100644 --- a/core/forkid/forkid_test.go +++ b/core/forkid/forkid_test.go @@ -45,34 +45,30 @@ func TestCreation(t *testing.T) { params.MainnetChainConfig, params.MainnetGenesisHash, []testcase{ - {0, 0, ID{Hash: checksumToBytes(0xfc64ec04), Next: 1150000}}, // Unsynced - {1149999, 0, ID{Hash: checksumToBytes(0xfc64ec04), Next: 1150000}}, // Last Frontier block - {1150000, 0, ID{Hash: checksumToBytes(0x97c2c34c), Next: 1920000}}, // First Homestead block - {1919999, 0, ID{Hash: checksumToBytes(0x97c2c34c), Next: 1920000}}, // Last Homestead block - {1920000, 0, ID{Hash: checksumToBytes(0x91d1f948), Next: 2463000}}, // First DAO block - {2462999, 0, ID{Hash: checksumToBytes(0x91d1f948), Next: 2463000}}, // Last DAO block - {2463000, 0, ID{Hash: checksumToBytes(0x7a64da13), Next: 2675000}}, // First Tangerine block - {2674999, 0, ID{Hash: checksumToBytes(0x7a64da13), Next: 2675000}}, // Last Tangerine block - {2675000, 0, ID{Hash: checksumToBytes(0x3edd5b10), Next: 4370000}}, // First Spurious block - {4369999, 0, ID{Hash: checksumToBytes(0x3edd5b10), Next: 4370000}}, // Last Spurious block - {4370000, 0, ID{Hash: checksumToBytes(0xa00bc324), Next: 7280000}}, // First Byzantium block - {7279999, 0, ID{Hash: checksumToBytes(0xa00bc324), Next: 7280000}}, // Last Byzantium block - {7280000, 0, ID{Hash: checksumToBytes(0x668db0af), Next: 9069000}}, // First and last Constantinople, first Petersburg block - {9068999, 0, ID{Hash: checksumToBytes(0x668db0af), Next: 9069000}}, // Last Petersburg block - {9069000, 0, ID{Hash: checksumToBytes(0x879d6e30), Next: 9200000}}, // First Istanbul and first Muir Glacier block - {9199999, 0, ID{Hash: checksumToBytes(0x879d6e30), Next: 9200000}}, // Last Istanbul and first Muir Glacier block - {9200000, 0, ID{Hash: checksumToBytes(0xe029e991), Next: 12244000}}, // First Muir Glacier block - {12243999, 0, ID{Hash: checksumToBytes(0xe029e991), Next: 12244000}}, // Last Muir Glacier block - {12244000, 0, ID{Hash: checksumToBytes(0x0eb440f6), Next: 12965000}}, // First Berlin block - {12964999, 0, ID{Hash: checksumToBytes(0x0eb440f6), Next: 12965000}}, // Last Berlin block - {12965000, 0, ID{Hash: checksumToBytes(0xb715077d), Next: 13773000}}, // First London block - {13772999, 0, ID{Hash: checksumToBytes(0xb715077d), Next: 13773000}}, // Last London block - {13773000, 0, ID{Hash: checksumToBytes(0x20c327fc), Next: 15050000}}, // First Arrow Glacier block - {15049999, 0, ID{Hash: checksumToBytes(0x20c327fc), Next: 15050000}}, // Last Arrow Glacier block - {15050000, 0, ID{Hash: checksumToBytes(0xf0afd0e3), Next: 1681338455}}, // First Gray Glacier block - {20000000, 1681338454, ID{Hash: checksumToBytes(0xf0afd0e3), Next: 1681338455}}, // Last Gray Glacier block - {20000000, 1681338455, ID{Hash: checksumToBytes(0xdce96c2d), Next: 0}}, // First Shanghai block - {30000000, 2000000000, ID{Hash: checksumToBytes(0xdce96c2d), Next: 0}}, // Future Shanghai block + {0, 0, ID{Hash: checksumToBytes(0xfc64ec04), Next: 1150000}}, // Unsynced + {1149999, 0, ID{Hash: checksumToBytes(0xfc64ec04), Next: 1150000}}, // Last Frontier block + {1150000, 0, ID{Hash: checksumToBytes(0x97c2c34c), Next: 1920000}}, // First Homestead block + {1919999, 0, ID{Hash: checksumToBytes(0x97c2c34c), Next: 1920000}}, // Last Homestead block + {1920000, 0, ID{Hash: checksumToBytes(0x91d1f948), Next: 2463000}}, // First DAO block + {2462999, 0, ID{Hash: checksumToBytes(0x91d1f948), Next: 2463000}}, // Last DAO block + {2463000, 0, ID{Hash: checksumToBytes(0x7a64da13), Next: 2675000}}, // First Tangerine block + {2674999, 0, ID{Hash: checksumToBytes(0x7a64da13), Next: 2675000}}, // Last Tangerine block + {2675000, 0, ID{Hash: checksumToBytes(0x3edd5b10), Next: 4370000}}, // First Spurious block + {4369999, 0, ID{Hash: checksumToBytes(0x3edd5b10), Next: 4370000}}, // Last Spurious block + {4370000, 0, ID{Hash: checksumToBytes(0xa00bc324), Next: 7280000}}, // First Byzantium block + {7279999, 0, ID{Hash: checksumToBytes(0xa00bc324), Next: 7280000}}, // Last Byzantium block + {7280000, 0, ID{Hash: checksumToBytes(0x668db0af), Next: 9069000}}, // First and last Constantinople, first Petersburg block + {9068999, 0, ID{Hash: checksumToBytes(0x668db0af), Next: 9069000}}, // Last Petersburg block + {9069000, 0, ID{Hash: checksumToBytes(0x879d6e30), Next: 9200000}}, // First Istanbul and first Muir Glacier block + {9199999, 0, ID{Hash: checksumToBytes(0x879d6e30), Next: 9200000}}, // Last Istanbul and first Muir Glacier block + {9200000, 0, ID{Hash: checksumToBytes(0xe029e991), Next: 12244000}}, // First Muir Glacier block + {12243999, 0, ID{Hash: checksumToBytes(0xe029e991), Next: 12244000}}, // Last Muir Glacier block + {12244000, 0, ID{Hash: checksumToBytes(0x0eb440f6), Next: 12965000}}, // First Berlin block + {12964999, 0, ID{Hash: checksumToBytes(0x0eb440f6), Next: 12965000}}, // Last Berlin block + {12965000, 0, ID{Hash: checksumToBytes(0xb715077d), Next: 13773000}}, // First London block + {13772999, 0, ID{Hash: checksumToBytes(0xb715077d), Next: 13773000}}, // Last London block + {13773000, 0, ID{Hash: checksumToBytes(0x20c327fc), Next: 15050000}}, // First Arrow Glacier block + {15049999, 0, ID{Hash: checksumToBytes(0x20c327fc), Next: 15050000}}, // Last Arrow Glacier block }, }, // Goerli test cases @@ -80,16 +76,12 @@ func TestCreation(t *testing.T) { params.GoerliChainConfig, params.GoerliGenesisHash, []testcase{ - {0, 0, ID{Hash: checksumToBytes(0xa3f5ab08), Next: 1561651}}, // Unsynced, last Frontier, Homestead, Tangerine, Spurious, Byzantium, Constantinople and first Petersburg block - {1561650, 0, ID{Hash: checksumToBytes(0xa3f5ab08), Next: 1561651}}, // Last Petersburg block - {1561651, 0, ID{Hash: checksumToBytes(0xc25efa5c), Next: 4460644}}, // First Istanbul block - {4460643, 0, ID{Hash: checksumToBytes(0xc25efa5c), Next: 4460644}}, // Last Istanbul block - {4460644, 0, ID{Hash: checksumToBytes(0x757a1c47), Next: 5062605}}, // First Berlin block - {5000000, 0, ID{Hash: checksumToBytes(0x757a1c47), Next: 5062605}}, // Last Berlin block - {5062605, 0, ID{Hash: checksumToBytes(0xB8C6299D), Next: 1678832736}}, // First London block - {6000000, 1678832735, ID{Hash: checksumToBytes(0xB8C6299D), Next: 1678832736}}, // Last London block - {6000001, 1678832736, ID{Hash: checksumToBytes(0xf9843abf), Next: 0}}, // First Shanghai block - {6500000, 2678832736, ID{Hash: checksumToBytes(0xf9843abf), Next: 0}}, // Future Shanghai block + {0, 0, ID{Hash: checksumToBytes(0xa3f5ab08), Next: 1561651}}, // Unsynced, last Frontier, Homestead, Tangerine, Spurious, Byzantium, Constantinople and first Petersburg block + {1561650, 0, ID{Hash: checksumToBytes(0xa3f5ab08), Next: 1561651}}, // Last Petersburg block + {1561651, 0, ID{Hash: checksumToBytes(0xc25efa5c), Next: 4460644}}, // First Istanbul block + {4460643, 0, ID{Hash: checksumToBytes(0xc25efa5c), Next: 4460644}}, // Last Istanbul block + {4460644, 0, ID{Hash: checksumToBytes(0x757a1c47), Next: 5062605}}, // First Berlin block + {5000000, 0, ID{Hash: checksumToBytes(0x757a1c47), Next: 5062605}}, // Last Berlin block }, }, // Sepolia test cases @@ -97,11 +89,8 @@ func TestCreation(t *testing.T) { params.SepoliaChainConfig, params.SepoliaGenesisHash, []testcase{ - {0, 0, ID{Hash: checksumToBytes(0xfe3366e7), Next: 1735371}}, // Unsynced, last Frontier, Homestead, Tangerine, Spurious, Byzantium, Constantinople, Petersburg, Istanbul, Berlin and first London block - {1735370, 0, ID{Hash: checksumToBytes(0xfe3366e7), Next: 1735371}}, // Last London block - {1735371, 0, ID{Hash: checksumToBytes(0xb96cbd13), Next: 1677557088}}, // First MergeNetsplit block - {1735372, 1677557087, ID{Hash: checksumToBytes(0xb96cbd13), Next: 1677557088}}, // Last MergeNetsplit block - {1735372, 1677557088, ID{Hash: checksumToBytes(0xf7f9bc08), Next: 0}}, // First Shanghai block + {0, 0, ID{Hash: checksumToBytes(0xfe3366e7), Next: 1735371}}, // Unsynced, last Frontier, Homestead, Tangerine, Spurious, Byzantium, Constantinople, Petersburg, Istanbul, Berlin and first London block + {1735370, 0, ID{Hash: checksumToBytes(0xfe3366e7), Next: 1735371}}, // Last London block }, }, } @@ -119,7 +108,7 @@ func TestCreation(t *testing.T) { func TestValidation(t *testing.T) { // Config that has not timestamp enabled legacyConfig := *params.MainnetChainConfig - legacyConfig.ShanghaiTime = nil + legacyConfig.ShanghaiBlock = nil tests := []struct { config *params.ChainConfig @@ -221,29 +210,14 @@ func TestValidation(t *testing.T) { // neither forks passed at neither nodes, they may mismatch, but we still connect for now. {params.MainnetChainConfig, 15050000, 0, ID{Hash: checksumToBytes(0xf0afd0e3), Next: math.MaxUint64}, nil}, - // Local is mainnet exactly on Shanghai, remote announces Gray Glacier + knowledge about Shanghai. Remote - // is simply out of sync, accept. - {params.MainnetChainConfig, 20000000, 1681338455, ID{Hash: checksumToBytes(0xf0afd0e3), Next: 1681338455}, nil}, - - // Local is mainnet Shanghai, remote announces Gray Glacier + knowledge about Shanghai. Remote - // is simply out of sync, accept. - {params.MainnetChainConfig, 20123456, 1681338456, ID{Hash: checksumToBytes(0xf0afd0e3), Next: 1681338455}, nil}, - // Local is mainnet Shanghai, remote announces Arrow Glacier + knowledge about Gray Glacier. Remote // is definitely out of sync. It may or may not need the Shanghai update, we don't know yet. {params.MainnetChainConfig, 20000000, 1681338455, ID{Hash: checksumToBytes(0x20c327fc), Next: 15050000}, nil}, - // Local is mainnet Gray Glacier, remote announces Shanghai. Local is out of sync, accept. - {params.MainnetChainConfig, 15050000, 0, ID{Hash: checksumToBytes(0xdce96c2d), Next: 0}, nil}, - // Local is mainnet Arrow Glacier, remote announces Gray Glacier, but is not aware of Shanghai. Local // out of sync. Local also knows about a future fork, but that is uncertain yet. {params.MainnetChainConfig, 13773000, 0, ID{Hash: checksumToBytes(0xf0afd0e3), Next: 0}, nil}, - // Local is mainnet Shanghai. remote announces Gray Glacier but is not aware of further forks. - // Remote needs software update. - {params.MainnetChainConfig, 20000000, 1681338455, ID{Hash: checksumToBytes(0xf0afd0e3), Next: 0}, ErrRemoteStale}, - // Local is mainnet Gray Glacier, and isn't aware of more forks. Remote announces Gray Glacier + // 0xffffffff. Local needs software update, reject. {params.MainnetChainConfig, 15050000, 0, ID{Hash: checksumToBytes(checksumUpdate(0xf0afd0e3, math.MaxUint64)), Next: 0}, ErrLocalIncompatibleOrStale}, @@ -266,13 +240,6 @@ func TestValidation(t *testing.T) { // Timestamp based tests //---------------------- - // Local is mainnet Shanghai, remote announces the same. No future fork is announced. - {params.MainnetChainConfig, 20000000, 1681338455, ID{Hash: checksumToBytes(0xdce96c2d), Next: 0}, nil}, - - // Local is mainnet Shanghai, remote announces the same. Remote also announces a next fork - // at time 0xffffffff, but that is uncertain. - {params.MainnetChainConfig, 20000000, 1681338455, ID{Hash: checksumToBytes(0xdce96c2d), Next: math.MaxUint64}, nil}, - // Local is mainnet currently in Shanghai only (so it's aware of Cancun), remote announces // also Shanghai, but it's not yet aware of Cancun (e.g. non updated node before the fork). // In this case we don't know if Cancun passed yet or not. diff --git a/core/genesis.go b/core/genesis.go index a6b2360983..06235986cc 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -298,7 +298,7 @@ func (e *GenesisMismatchError) Error() string { // ChainOverrides contains the changes to chain config. type ChainOverrides struct { - OverrideShanghai *uint64 + OverrideShanghai *big.Int } // SetupGenesisBlock writes or updates the genesis block in db. @@ -326,9 +326,8 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *trie.Database, gen applyOverrides := func(config *params.ChainConfig) { if config != nil { - // TODO marcello double check if overrides != nil && overrides.OverrideShanghai != nil { - config.ShanghaiTime = overrides.OverrideShanghai + config.ShanghaiBlock = overrides.OverrideShanghai } } } @@ -529,9 +528,9 @@ func (g *Genesis) ToBlock() *types.Block { var withdrawals []*types.Withdrawal - if g.Config != nil && g.Config.IsShanghai(g.Timestamp) { - head.WithdrawalsHash = &types.EmptyWithdrawalsHash - withdrawals = make([]*types.Withdrawal, 0) + if g.Config != nil && g.Config.IsShanghai(new(big.Int).SetUint64(g.Number)) { + head.WithdrawalsHash = nil + withdrawals = nil } return types.NewBlock(head, nil, nil, nil, trie.NewStackTrie(nil)).WithWithdrawals(withdrawals) diff --git a/core/state/statedb.go b/core/state/statedb.go index 9e680fae61..c68b7a133c 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -1595,7 +1595,6 @@ func (s *StateDB) Prepare(rules params.Rules, sender, coinbase common.Address, d al.AddSlot(el.Address, key) } } - // TODO marcello double check if rules.IsShanghai { // EIP-3651: warm coinbase al.AddAddress(coinbase) } diff --git a/core/state_processor.go b/core/state_processor.go index 019849e867..4833919364 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -101,10 +101,13 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg } // Fail if Shanghai not enabled and len(withdrawals) is non-zero. withdrawals := block.Withdrawals() - // TODO marcello double check - if len(withdrawals) > 0 && !p.config.IsShanghai(block.Time()) { + if !p.config.IsShanghai(block.Number()) && withdrawals != nil { return nil, nil, 0, fmt.Errorf("withdrawals before shanghai") } + // Bor does not support withdrawals + if withdrawals != nil { + withdrawals = nil + } // Finalize the block, applying any consensus engine specific extras (e.g. block rewards) p.engine.Finalize(p.bc, header, statedb, block.Transactions(), block.Uncles(), withdrawals) diff --git a/core/state_processor_test.go b/core/state_processor_test.go index 16dc09dedf..7fd22c3b00 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -364,9 +364,8 @@ func TestStateProcessorErrors(t *testing.T) { MergeNetsplitBlock: big.NewInt(0), TerminalTotalDifficulty: big.NewInt(0), TerminalTotalDifficultyPassed: true, - // TODO marcello double check - ShanghaiTime: u64(0), - Bor: ¶ms.BorConfig{BurntContract: map[string]string{"0": "0x000000000000000000000000000000000000dead"}}, + ShanghaiBlock: big.NewInt(0), + Bor: ¶ms.BorConfig{BurntContract: map[string]string{"0": "0x000000000000000000000000000000000000dead"}}, }, Alloc: GenesisAlloc{ common.HexToAddress("0x71562b71999873DB5b286dF957af199Ec94617F7"): GenesisAccount{ @@ -442,11 +441,12 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr Time: parent.Time() + 10, UncleHash: types.EmptyUncleHash, } + if config.IsLondon(header.Number) { header.BaseFee = misc.CalcBaseFee(config, parent.Header()) } - // TODO marcello double check - if config.IsShanghai(header.Time) { + + if config.IsShanghai(header.Number) { header.WithdrawalsHash = &types.EmptyWithdrawalsHash } @@ -471,8 +471,7 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr header.Root = common.BytesToHash(hasher.Sum(nil)) // Assemble and return the final block for sealing - // TODO marcello double check - if config.IsShanghai(header.Time) { + if config.IsShanghai(header.Number) { return types.NewBlockWithWithdrawals(header, txs, nil, receipts, []*types.Withdrawal{}, trie.NewStackTrie(nil)) } diff --git a/core/state_transition.go b/core/state_transition.go index b71fcbf88d..7042d4b87e 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -403,7 +403,6 @@ func (st *StateTransition) TransitionDb(interruptCtx context.Context) (*Executio } // Check whether the init code size has been exceeded. - // TODO marcello double check if rules.IsShanghai && contractCreation && len(msg.Data) > params.MaxInitCodeSize { return nil, fmt.Errorf("%w: code size %v limit %v", ErrMaxInitCodeSizeExceeded, len(msg.Data), params.MaxInitCodeSize) } diff --git a/core/txpool/txpool.go b/core/txpool/txpool.go index 82ee2fafa8..e6c248cf16 100644 --- a/core/txpool/txpool.go +++ b/core/txpool/txpool.go @@ -1900,7 +1900,7 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) { pool.istanbul.Store(pool.chainconfig.IsIstanbul(next)) pool.eip2718.Store(pool.chainconfig.IsBerlin(next)) pool.eip1559.Store(pool.chainconfig.IsLondon(next)) - pool.shanghai.Store(pool.chainconfig.IsShanghai(uint64(time.Now().Unix()))) + pool.shanghai.Store(pool.chainconfig.IsShanghai(next)) } // promoteExecutables moves transactions that have become processable from the diff --git a/core/vm/evm.go b/core/vm/evm.go index 9c26831bc6..6d542cdee3 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -134,8 +134,7 @@ func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig StateDB: statedb, Config: config, chainConfig: chainConfig, - // TODO marcello double check - chainRules: chainConfig.Rules(blockCtx.BlockNumber, blockCtx.Random != nil, blockCtx.Time), + chainRules: chainConfig.Rules(blockCtx.BlockNumber, blockCtx.Random != nil, blockCtx.Time), } evm.interpreter = NewEVMInterpreter(evm) diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index 0a10ae2750..2b961bd532 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -132,7 +132,6 @@ func NewEVMInterpreter(evm *EVM) *EVMInterpreter { var table *JumpTable switch { - // TODO marcello double check case evm.chainRules.IsShanghai: table = &shanghaiInstructionSet case evm.chainRules.IsMerge: diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go index c98455b8f6..606f8b8af9 100644 --- a/core/vm/jump_table.go +++ b/core/vm/jump_table.go @@ -90,12 +90,15 @@ func newShanghaiInstructionSet() JumpTable { func newMergeInstructionSet() JumpTable { instructionSet := newLondonInstructionSet() - instructionSet[PREVRANDAO] = &operation{ - execute: opRandom, - constantGas: GasQuickStep, - minStack: minStack(0, 1), - maxStack: maxStack(0, 1), - } + + // disabling in pos due to incompatibility with prevrandao + + // instructionSet[PREVRANDAO] = &operation{ + // execute: opRandom, + // constantGas: GasQuickStep, + // minStack: minStack(0, 1), + // maxStack: maxStack(0, 1), + // } return validate(instructionSet) } diff --git a/eth/api.go b/eth/api.go index 9336880221..b953be2d09 100644 --- a/eth/api.go +++ b/eth/api.go @@ -277,6 +277,9 @@ func (api *DebugAPI) DumpBlock(blockNr rpc.BlockNumber) (state.Dump, error) { // both the pending block as well as the pending state from // the miner and operate on those _, stateDb := api.eth.miner.Pending() + if stateDb == nil { + return state.Dump{}, errors.New("pending state is not available") + } return stateDb.RawDump(opts), nil } @@ -385,6 +388,9 @@ func (api *DebugAPI) AccountRange(blockNrOrHash rpc.BlockNumberOrHash, start hex // both the pending block as well as the pending state from // the miner and operate on those _, stateDb = api.eth.miner.Pending() + if stateDb == nil { + return state.IteratorDump{}, errors.New("pending state is not available") + } } else { var header *types.Header if number == rpc.LatestBlockNumber { diff --git a/eth/api_backend.go b/eth/api_backend.go index a6f6449435..d5935ac4f6 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -68,6 +68,9 @@ func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumb // Pending block is only known by the miner if number == rpc.PendingBlockNumber { block := b.eth.miner.PendingBlock() + if block == nil { + return nil, errors.New("pending block is not available") + } return block.Header(), nil } // Otherwise resolve and return the block @@ -136,6 +139,9 @@ func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumbe // Pending block is only known by the miner if number == rpc.PendingBlockNumber { block := b.eth.miner.PendingBlock() + if block == nil { + return nil, errors.New("pending block is not available") + } return block, nil } // Otherwise resolve and return the block @@ -217,6 +223,9 @@ func (b *EthAPIBackend) StateAndHeaderByNumber(ctx context.Context, number rpc.B // Pending state is only known by the miner if number == rpc.PendingBlockNumber { block, state := b.eth.miner.Pending() + if block == nil || state == nil { + return nil, nil, errors.New("pending state is not available") + } return state, block.Header(), nil } // Otherwise resolve the block number and return its state diff --git a/eth/catalyst/api.go b/eth/catalyst/api.go index a6a0a08d2e..e667fc0cf0 100644 --- a/eth/catalyst/api.go +++ b/eth/catalyst/api.go @@ -165,46 +165,46 @@ func NewConsensusAPI(eth *eth.Ethereum) *ConsensusAPI { // // If there are payloadAttributes: we try to assemble a block with the payloadAttributes // and return its payloadID. -func (api *ConsensusAPI) ForkchoiceUpdatedV1(update engine.ForkchoiceStateV1, payloadAttributes *engine.PayloadAttributes) (engine.ForkChoiceResponse, error) { - if payloadAttributes != nil { - if payloadAttributes.Withdrawals != nil { - return engine.STATUS_INVALID, engine.InvalidParams.With(fmt.Errorf("withdrawals not supported in V1")) - } +// func (api *ConsensusAPI) ForkchoiceUpdatedV1(update engine.ForkchoiceStateV1, payloadAttributes *engine.PayloadAttributes) (engine.ForkChoiceResponse, error) { +// if payloadAttributes != nil { +// if payloadAttributes.Withdrawals != nil { +// return engine.STATUS_INVALID, engine.InvalidParams.With(fmt.Errorf("withdrawals not supported in V1")) +// } - if api.eth.BlockChain().Config().IsShanghai(payloadAttributes.Timestamp) { - return engine.STATUS_INVALID, engine.InvalidParams.With(fmt.Errorf("forkChoiceUpdateV1 called post-shanghai")) - } - } +// if api.eth.BlockChain().Config().IsShanghai(payloadAttributes.Timestamp) { +// return engine.STATUS_INVALID, engine.InvalidParams.With(fmt.Errorf("forkChoiceUpdateV1 called post-shanghai")) +// } +// } - return api.forkchoiceUpdated(update, payloadAttributes) -} +// return api.forkchoiceUpdated(update, payloadAttributes) +// } // ForkchoiceUpdatedV2 is equivalent to V1 with the addition of withdrawals in the payload attributes. -func (api *ConsensusAPI) ForkchoiceUpdatedV2(update engine.ForkchoiceStateV1, payloadAttributes *engine.PayloadAttributes) (engine.ForkChoiceResponse, error) { - if payloadAttributes != nil { - if err := api.verifyPayloadAttributes(payloadAttributes); err != nil { - return engine.STATUS_INVALID, engine.InvalidParams.With(err) - } - } - - return api.forkchoiceUpdated(update, payloadAttributes) -} - -func (api *ConsensusAPI) verifyPayloadAttributes(attr *engine.PayloadAttributes) error { - if !api.eth.BlockChain().Config().IsShanghai(attr.Timestamp) { - // Reject payload attributes with withdrawals before shanghai - if attr.Withdrawals != nil { - return errors.New("withdrawals before shanghai") - } - } else { - // Reject payload attributes with nil withdrawals after shanghai - if attr.Withdrawals == nil { - return errors.New("missing withdrawals list") - } - } - - return nil -} +// func (api *ConsensusAPI) ForkchoiceUpdatedV2(update engine.ForkchoiceStateV1, payloadAttributes *engine.PayloadAttributes) (engine.ForkChoiceResponse, error) { +// if payloadAttributes != nil { +// if err := api.verifyPayloadAttributes(payloadAttributes); err != nil { +// return engine.STATUS_INVALID, engine.InvalidParams.With(err) +// } +// } + +// return api.forkchoiceUpdated(update, payloadAttributes) +// } + +// func (api *ConsensusAPI) verifyPayloadAttributes(attr *engine.PayloadAttributes) error { +// if !api.eth.BlockChain().Config().IsShanghai(attr.Timestamp) { +// // Reject payload attributes with withdrawals before shanghai +// if attr.Withdrawals != nil { +// return errors.New("withdrawals before shanghai") +// } +// } else { +// // Reject payload attributes with nil withdrawals after shanghai +// if attr.Withdrawals == nil { +// return errors.New("missing withdrawals list") +// } +// } + +// return nil +// } // nolint:gocognit func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payloadAttributes *engine.PayloadAttributes) (engine.ForkChoiceResponse, error) { @@ -454,18 +454,18 @@ func (api *ConsensusAPI) NewPayloadV1(params engine.ExecutableData) (engine.Payl return api.newPayload(params) } -// NewPayloadV2 creates an Eth1 block, inserts it in the chain, and returns the status of the chain. -func (api *ConsensusAPI) NewPayloadV2(params engine.ExecutableData) (engine.PayloadStatusV1, error) { - if api.eth.BlockChain().Config().IsShanghai(params.Timestamp) { - if params.Withdrawals == nil { - return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(fmt.Errorf("nil withdrawals post-shanghai")) - } - } else if params.Withdrawals != nil { - return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(fmt.Errorf("non-nil withdrawals pre-shanghai")) - } - - return api.newPayload(params) -} +// // NewPayloadV2 creates an Eth1 block, inserts it in the chain, and returns the status of the chain. +// func (api *ConsensusAPI) NewPayloadV2(params engine.ExecutableData) (engine.PayloadStatusV1, error) { +// if api.eth.BlockChain().Config().IsShanghai(params.Timestamp) { +// if params.Withdrawals == nil { +// return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(fmt.Errorf("nil withdrawals post-shanghai")) +// } +// } else if params.Withdrawals != nil { +// return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(fmt.Errorf("non-nil withdrawals pre-shanghai")) +// } + +// return api.newPayload(params) +// } func (api *ConsensusAPI) newPayload(params engine.ExecutableData) (engine.PayloadStatusV1, error) { // The locking here is, strictly, not required. Without these locks, this can happen: diff --git a/eth/catalyst/api_test.go b/eth/catalyst/api_test.go index 72be8ed121..1cce150eb0 100644 --- a/eth/catalyst/api_test.go +++ b/eth/catalyst/api_test.go @@ -16,628 +16,596 @@ package catalyst -import ( - "bytes" - "context" - crand "crypto/rand" - "fmt" - "math/big" - "math/rand" - "reflect" - "sync" - "testing" - "time" - - "github.com/ethereum/go-ethereum/beacon/engine" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ethereum/go-ethereum/consensus" - beaconConsensus "github.com/ethereum/go-ethereum/consensus/beacon" - "github.com/ethereum/go-ethereum/consensus/ethash" - "github.com/ethereum/go-ethereum/core" - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/eth" - "github.com/ethereum/go-ethereum/eth/downloader" - "github.com/ethereum/go-ethereum/eth/ethconfig" - "github.com/ethereum/go-ethereum/miner" - "github.com/ethereum/go-ethereum/node" - "github.com/ethereum/go-ethereum/p2p" - "github.com/ethereum/go-ethereum/params" - "github.com/ethereum/go-ethereum/rpc" - "github.com/ethereum/go-ethereum/trie" -) - -var ( - // testKey is a private key to use for funding a tester account. - testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") - - // testAddr is the Ethereum address of the tester account. - testAddr = crypto.PubkeyToAddress(testKey.PublicKey) - - testBalance = big.NewInt(2e18) -) - -func generateMergeChain(n int, merged bool) (*core.Genesis, []*types.Block) { - config := *params.AllEthashProtocolChanges - engine := consensus.Engine(beaconConsensus.New(ethash.NewFaker())) - - if merged { - config.TerminalTotalDifficulty = common.Big0 - config.TerminalTotalDifficultyPassed = true - engine = beaconConsensus.NewFaker() - } - - genesis := &core.Genesis{ - Config: &config, - Alloc: core.GenesisAlloc{testAddr: {Balance: testBalance}}, - ExtraData: []byte("test genesis"), - Timestamp: 9000, - BaseFee: big.NewInt(params.InitialBaseFee), - Difficulty: big.NewInt(0), - } - testNonce := uint64(0) - generate := func(i int, g *core.BlockGen) { - g.OffsetTime(5) - g.SetExtra([]byte("test")) - - tx, _ := types.SignTx(types.NewTransaction(testNonce, common.HexToAddress("0x9a9070028361F7AAbeB3f2F2Dc07F82C4a98A02a"), big.NewInt(1), params.TxGas, big.NewInt(params.InitialBaseFee*2), nil), types.LatestSigner(&config), testKey) - g.AddTx(tx) - - testNonce++ - } - _, blocks, _ := core.GenerateChainWithGenesis(genesis, engine, n, generate) - - if !merged { - totalDifficulty := big.NewInt(0) - for _, b := range blocks { - totalDifficulty.Add(totalDifficulty, b.Difficulty()) - } - - config.TerminalTotalDifficulty = totalDifficulty - } - - return genesis, blocks -} - -func TestEth2AssembleBlock(t *testing.T) { - t.Skip("bor due to burn contract") - - genesis, blocks := generateMergeChain(10, false) - - n, ethservice := startEthService(t, genesis, blocks) - defer n.Close() - - api := NewConsensusAPI(ethservice) - signer := types.NewEIP155Signer(ethservice.BlockChain().Config().ChainID) - - tx, err := types.SignTx(types.NewTransaction(uint64(10), blocks[9].Coinbase(), big.NewInt(1000), params.TxGas, big.NewInt(params.InitialBaseFee), nil), signer, testKey) - if err != nil { - t.Fatalf("error signing transaction, err=%v", err) - } - - ethservice.TxPool().AddLocal(tx) - - blockParams := engine.PayloadAttributes{ - Timestamp: blocks[9].Time() + 5, - } - // The miner needs to pick up on the txs in the pool, so a few retries might be - // needed. - if _, testErr := assembleWithTransactions(api, blocks[9].Hash(), &blockParams, 1); testErr != nil { - t.Fatal(testErr) - } -} - -// assembleWithTransactions tries to assemble a block, retrying until it has 'want', -// number of transactions in it, or it has retried three times. -func assembleWithTransactions(api *ConsensusAPI, parentHash common.Hash, params *engine.PayloadAttributes, want int) (execData *engine.ExecutableData, err error) { - for retries := 3; retries > 0; retries-- { - execData, err = assembleBlock(api, parentHash, params) - if err != nil { - return nil, err - } - - if have, want := len(execData.Transactions), want; have != want { - err = fmt.Errorf("invalid number of transactions, have %d want %d", have, want) - continue - } - - return execData, nil - } - - return nil, err -} - -func TestEth2AssembleBlockWithAnotherBlocksTxs(t *testing.T) { - t.Skip("bor due to burn contract") - - genesis, blocks := generateMergeChain(10, false) - - n, ethservice := startEthService(t, genesis, blocks[:9]) - defer n.Close() - - api := NewConsensusAPI(ethservice) - - // Put the 10th block's tx in the pool and produce a new block - api.eth.TxPool().AddRemotesSync(blocks[9].Transactions()) - - blockParams := engine.PayloadAttributes{ - Timestamp: blocks[8].Time() + 5, - } - // The miner needs to pick up on the txs in the pool, so a few retries might be - // needed. - if _, err := assembleWithTransactions(api, blocks[8].Hash(), &blockParams, blocks[9].Transactions().Len()); err != nil { - t.Fatal(err) - } -} - -func TestSetHeadBeforeTotalDifficulty(t *testing.T) { - genesis, blocks := generateMergeChain(10, false) - - n, ethservice := startEthService(t, genesis, blocks) - defer n.Close() - - api := NewConsensusAPI(ethservice) - fcState := engine.ForkchoiceStateV1{ - HeadBlockHash: blocks[5].Hash(), - SafeBlockHash: common.Hash{}, - FinalizedBlockHash: common.Hash{}, - } - - if resp, err := api.ForkchoiceUpdatedV1(fcState, nil); err != nil { - t.Errorf("fork choice updated should not error: %v", err) - } else if resp.PayloadStatus.Status != engine.INVALID_TERMINAL_BLOCK.Status { - t.Errorf("fork choice updated before total terminal difficulty should be INVALID") - } -} - -func TestEth2PrepareAndGetPayload(t *testing.T) { - genesis, blocks := generateMergeChain(10, false) - // We need to properly set the terminal total difficulty - genesis.Config.TerminalTotalDifficulty.Sub(genesis.Config.TerminalTotalDifficulty, blocks[9].Difficulty()) - n, ethservice := startEthService(t, genesis, blocks[:9]) - - defer n.Close() - - api := NewConsensusAPI(ethservice) - - // Put the 10th block's tx in the pool and produce a new block - ethservice.TxPool().AddLocals(blocks[9].Transactions()) - - blockParams := engine.PayloadAttributes{ - Timestamp: blocks[8].Time() + 5, - } - fcState := engine.ForkchoiceStateV1{ - HeadBlockHash: blocks[8].Hash(), - SafeBlockHash: common.Hash{}, - FinalizedBlockHash: common.Hash{}, - } - _, err := api.ForkchoiceUpdatedV1(fcState, &blockParams) - - if err != nil { - t.Fatalf("error preparing payload, err=%v", err) - } - // give the payload some time to be built - time.Sleep(100 * time.Millisecond) - - payloadID := (&miner.BuildPayloadArgs{ - Parent: fcState.HeadBlockHash, - Timestamp: blockParams.Timestamp, - FeeRecipient: blockParams.SuggestedFeeRecipient, - Random: blockParams.Random, - }).Id() - execData, err := api.GetPayloadV1(payloadID) - - if err != nil { - t.Fatalf("error getting payload, err=%v", err) - } - - if len(execData.Transactions) != blocks[9].Transactions().Len() { - t.Fatalf("invalid number of transactions %d != 1", len(execData.Transactions)) - } - // Test invalid payloadID - var invPayload engine.PayloadID - - copy(invPayload[:], payloadID[:]) - invPayload[0] = ^invPayload[0] - _, err = api.GetPayloadV1(invPayload) - - if err == nil { - t.Fatal("expected error retrieving invalid payload") - } -} - -func checkLogEvents(t *testing.T, logsCh <-chan []*types.Log, rmLogsCh <-chan core.RemovedLogsEvent, wantNew, wantRemoved int) { - t.Helper() - - if len(logsCh) != wantNew { - t.Fatalf("wrong number of log events: got %d, want %d", len(logsCh), wantNew) - } - - if len(rmLogsCh) != wantRemoved { - t.Fatalf("wrong number of removed log events: got %d, want %d", len(rmLogsCh), wantRemoved) - } - // Drain events. - for i := 0; i < len(logsCh); i++ { - <-logsCh - } - - for i := 0; i < len(rmLogsCh); i++ { - <-rmLogsCh - } -} - -func TestInvalidPayloadTimestamp(t *testing.T) { - genesis, preMergeBlocks := generateMergeChain(10, false) - - n, ethservice := startEthService(t, genesis, preMergeBlocks) - defer n.Close() - - var ( - api = NewConsensusAPI(ethservice) - parent = ethservice.BlockChain().CurrentBlock() - ) - - tests := []struct { - time uint64 - shouldErr bool - }{ - {0, true}, - {parent.Time, true}, - {parent.Time - 1, true}, - - // TODO (MariusVanDerWijden) following tests are currently broken, - // fixed in upcoming merge-kiln-v2 pr - //{parent.Time() + 1, false}, - //{uint64(time.Now().Unix()) + uint64(time.Minute), false}, - } - - for i, test := range tests { - t.Run(fmt.Sprintf("Timestamp test: %v", i), func(t *testing.T) { - params := engine.PayloadAttributes{ - Timestamp: test.time, - Random: crypto.Keccak256Hash([]byte{byte(123)}), - SuggestedFeeRecipient: parent.Coinbase, - } - fcState := engine.ForkchoiceStateV1{ - HeadBlockHash: parent.Hash(), - SafeBlockHash: common.Hash{}, - FinalizedBlockHash: common.Hash{}, - } - - _, err := api.ForkchoiceUpdatedV1(fcState, ¶ms) - if test.shouldErr && err == nil { - t.Fatalf("expected error preparing payload with invalid timestamp, err=%v", err) - } else if !test.shouldErr && err != nil { - t.Fatalf("error preparing payload with valid timestamp, err=%v", err) - } - }) - } -} +// var ( +// // testKey is a private key to use for funding a tester account. +// testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") + +// // testAddr is the Ethereum address of the tester account. +// testAddr = crypto.PubkeyToAddress(testKey.PublicKey) + +// testBalance = big.NewInt(2e18) +// ) + +// func generateMergeChain(n int, merged bool) (*core.Genesis, []*types.Block) { +// config := *params.AllEthashProtocolChanges +// engine := consensus.Engine(beaconConsensus.New(ethash.NewFaker())) + +// if merged { +// config.TerminalTotalDifficulty = common.Big0 +// config.TerminalTotalDifficultyPassed = true +// engine = beaconConsensus.NewFaker() +// } + +// genesis := &core.Genesis{ +// Config: &config, +// Alloc: core.GenesisAlloc{testAddr: {Balance: testBalance}}, +// ExtraData: []byte("test genesis"), +// Timestamp: 9000, +// BaseFee: big.NewInt(params.InitialBaseFee), +// Difficulty: big.NewInt(0), +// } +// testNonce := uint64(0) +// generate := func(i int, g *core.BlockGen) { +// g.OffsetTime(5) +// g.SetExtra([]byte("test")) + +// tx, _ := types.SignTx(types.NewTransaction(testNonce, common.HexToAddress("0x9a9070028361F7AAbeB3f2F2Dc07F82C4a98A02a"), big.NewInt(1), params.TxGas, big.NewInt(params.InitialBaseFee*2), nil), types.LatestSigner(&config), testKey) +// g.AddTx(tx) + +// testNonce++ +// } +// _, blocks, _ := core.GenerateChainWithGenesis(genesis, engine, n, generate) + +// if !merged { +// totalDifficulty := big.NewInt(0) +// for _, b := range blocks { +// totalDifficulty.Add(totalDifficulty, b.Difficulty()) +// } + +// config.TerminalTotalDifficulty = totalDifficulty +// } + +// return genesis, blocks +// } + +// func TestEth2AssembleBlock(t *testing.T) { +// t.Skip("bor due to burn contract") + +// genesis, blocks := generateMergeChain(10, false) + +// n, ethservice := startEthService(t, genesis, blocks) +// defer n.Close() + +// api := NewConsensusAPI(ethservice) +// signer := types.NewEIP155Signer(ethservice.BlockChain().Config().ChainID) + +// tx, err := types.SignTx(types.NewTransaction(uint64(10), blocks[9].Coinbase(), big.NewInt(1000), params.TxGas, big.NewInt(params.InitialBaseFee), nil), signer, testKey) +// if err != nil { +// t.Fatalf("error signing transaction, err=%v", err) +// } + +// ethservice.TxPool().AddLocal(tx) + +// blockParams := engine.PayloadAttributes{ +// Timestamp: blocks[9].Time() + 5, +// } +// // The miner needs to pick up on the txs in the pool, so a few retries might be +// // needed. +// if _, testErr := assembleWithTransactions(api, blocks[9].Hash(), &blockParams, 1); testErr != nil { +// t.Fatal(testErr) +// } +// } + +// // assembleWithTransactions tries to assemble a block, retrying until it has 'want', +// // number of transactions in it, or it has retried three times. +// func assembleWithTransactions(api *ConsensusAPI, parentHash common.Hash, params *engine.PayloadAttributes, want int) (execData *engine.ExecutableData, err error) { +// for retries := 3; retries > 0; retries-- { +// execData, err = assembleBlock(api, parentHash, params) +// if err != nil { +// return nil, err +// } + +// if have, want := len(execData.Transactions), want; have != want { +// err = fmt.Errorf("invalid number of transactions, have %d want %d", have, want) +// continue +// } + +// return execData, nil +// } + +// return nil, err +// } + +// func TestEth2AssembleBlockWithAnotherBlocksTxs(t *testing.T) { +// t.Skip("bor due to burn contract") + +// genesis, blocks := generateMergeChain(10, false) + +// n, ethservice := startEthService(t, genesis, blocks[:9]) +// defer n.Close() + +// api := NewConsensusAPI(ethservice) + +// // Put the 10th block's tx in the pool and produce a new block +// api.eth.TxPool().AddRemotesSync(blocks[9].Transactions()) + +// blockParams := engine.PayloadAttributes{ +// Timestamp: blocks[8].Time() + 5, +// } +// // The miner needs to pick up on the txs in the pool, so a few retries might be +// // needed. +// if _, err := assembleWithTransactions(api, blocks[8].Hash(), &blockParams, blocks[9].Transactions().Len()); err != nil { +// t.Fatal(err) +// } +// } + +// func TestSetHeadBeforeTotalDifficulty(t *testing.T) { +// genesis, blocks := generateMergeChain(10, false) + +// n, ethservice := startEthService(t, genesis, blocks) +// defer n.Close() + +// api := NewConsensusAPI(ethservice) +// fcState := engine.ForkchoiceStateV1{ +// HeadBlockHash: blocks[5].Hash(), +// SafeBlockHash: common.Hash{}, +// FinalizedBlockHash: common.Hash{}, +// } + +// if resp, err := api.ForkchoiceUpdatedV1(fcState, nil); err != nil { +// t.Errorf("fork choice updated should not error: %v", err) +// } else if resp.PayloadStatus.Status != engine.INVALID_TERMINAL_BLOCK.Status { +// t.Errorf("fork choice updated before total terminal difficulty should be INVALID") +// } +// } + +// func TestEth2PrepareAndGetPayload(t *testing.T) { +// genesis, blocks := generateMergeChain(10, false) +// // We need to properly set the terminal total difficulty +// genesis.Config.TerminalTotalDifficulty.Sub(genesis.Config.TerminalTotalDifficulty, blocks[9].Difficulty()) +// n, ethservice := startEthService(t, genesis, blocks[:9]) + +// defer n.Close() + +// api := NewConsensusAPI(ethservice) + +// // Put the 10th block's tx in the pool and produce a new block +// ethservice.TxPool().AddLocals(blocks[9].Transactions()) + +// blockParams := engine.PayloadAttributes{ +// Timestamp: blocks[8].Time() + 5, +// } +// fcState := engine.ForkchoiceStateV1{ +// HeadBlockHash: blocks[8].Hash(), +// SafeBlockHash: common.Hash{}, +// FinalizedBlockHash: common.Hash{}, +// } +// _, err := api.ForkchoiceUpdatedV1(fcState, &blockParams) + +// if err != nil { +// t.Fatalf("error preparing payload, err=%v", err) +// } +// // give the payload some time to be built +// time.Sleep(100 * time.Millisecond) + +// payloadID := (&miner.BuildPayloadArgs{ +// Parent: fcState.HeadBlockHash, +// Timestamp: blockParams.Timestamp, +// FeeRecipient: blockParams.SuggestedFeeRecipient, +// Random: blockParams.Random, +// }).Id() +// execData, err := api.GetPayloadV1(payloadID) + +// if err != nil { +// t.Fatalf("error getting payload, err=%v", err) +// } + +// if len(execData.Transactions) != blocks[9].Transactions().Len() { +// t.Fatalf("invalid number of transactions %d != 1", len(execData.Transactions)) +// } +// // Test invalid payloadID +// var invPayload engine.PayloadID + +// copy(invPayload[:], payloadID[:]) +// invPayload[0] = ^invPayload[0] +// _, err = api.GetPayloadV1(invPayload) + +// if err == nil { +// t.Fatal("expected error retrieving invalid payload") +// } +// } + +// func checkLogEvents(t *testing.T, logsCh <-chan []*types.Log, rmLogsCh <-chan core.RemovedLogsEvent, wantNew, wantRemoved int) { +// t.Helper() + +// if len(logsCh) != wantNew { +// t.Fatalf("wrong number of log events: got %d, want %d", len(logsCh), wantNew) +// } + +// if len(rmLogsCh) != wantRemoved { +// t.Fatalf("wrong number of removed log events: got %d, want %d", len(rmLogsCh), wantRemoved) +// } +// // Drain events. +// for i := 0; i < len(logsCh); i++ { +// <-logsCh +// } + +// for i := 0; i < len(rmLogsCh); i++ { +// <-rmLogsCh +// } +// } + +// func TestInvalidPayloadTimestamp(t *testing.T) { +// genesis, preMergeBlocks := generateMergeChain(10, false) + +// n, ethservice := startEthService(t, genesis, preMergeBlocks) +// defer n.Close() + +// var ( +// api = NewConsensusAPI(ethservice) +// parent = ethservice.BlockChain().CurrentBlock() +// ) + +// tests := []struct { +// time uint64 +// shouldErr bool +// }{ +// {0, true}, +// {parent.Time, true}, +// {parent.Time - 1, true}, + +// // TODO (MariusVanDerWijden) following tests are currently broken, +// // fixed in upcoming merge-kiln-v2 pr +// //{parent.Time() + 1, false}, +// //{uint64(time.Now().Unix()) + uint64(time.Minute), false}, +// } + +// for i, test := range tests { +// t.Run(fmt.Sprintf("Timestamp test: %v", i), func(t *testing.T) { +// params := engine.PayloadAttributes{ +// Timestamp: test.time, +// Random: crypto.Keccak256Hash([]byte{byte(123)}), +// SuggestedFeeRecipient: parent.Coinbase, +// } +// fcState := engine.ForkchoiceStateV1{ +// HeadBlockHash: parent.Hash(), +// SafeBlockHash: common.Hash{}, +// FinalizedBlockHash: common.Hash{}, +// } + +// _, err := api.ForkchoiceUpdatedV1(fcState, ¶ms) +// if test.shouldErr && err == nil { +// t.Fatalf("expected error preparing payload with invalid timestamp, err=%v", err) +// } else if !test.shouldErr && err != nil { +// t.Fatalf("error preparing payload with valid timestamp, err=%v", err) +// } +// }) +// } +// } // nolint:goconst -func TestEth2NewBlock(t *testing.T) { - t.Skip("ETH2 in Bor") - - genesis, preMergeBlocks := generateMergeChain(10, false) - - n, ethservice := startEthService(t, genesis, preMergeBlocks) - defer n.Close() - - var ( - api = NewConsensusAPI(ethservice) - parent = preMergeBlocks[len(preMergeBlocks)-1] - - // This EVM code generates a log when the contract is created. - logCode = common.Hex2Bytes("60606040525b7f24ec1d3ff24c2f6ff210738839dbc339cd45a5294d85c79361016243157aae7b60405180905060405180910390a15b600a8060416000396000f360606040526008565b00") - ) - // The event channels. - newLogCh := make(chan []*types.Log, 10) - rmLogsCh := make(chan core.RemovedLogsEvent, 10) - - ethservice.BlockChain().SubscribeLogsEvent(newLogCh) - ethservice.BlockChain().SubscribeRemovedLogsEvent(rmLogsCh) - - for i := 0; i < 10; i++ { - statedb, _ := ethservice.BlockChain().StateAt(parent.Root()) - nonce := statedb.GetNonce(testAddr) - tx, _ := types.SignTx(types.NewContractCreation(nonce, new(big.Int), 1000000, big.NewInt(2*params.InitialBaseFee), logCode), types.LatestSigner(ethservice.BlockChain().Config()), testKey) - ethservice.TxPool().AddLocal(tx) - - execData, err := assembleWithTransactions(api, parent.Hash(), &engine.PayloadAttributes{ - Timestamp: parent.Time() + 5, - }, 1) - if err != nil { - t.Fatalf("Failed to create the executable data %v", err) - } - - block, err := engine.ExecutableDataToBlock(*execData) - if err != nil { - t.Fatalf("Failed to convert executable data to block %v", err) - } - - newResp, err := api.NewPayloadV1(*execData) - - switch { - case err != nil: - t.Fatalf("Failed to insert block: %v", err) - case newResp.Status != "VALID": - t.Fatalf("Failed to insert block: %v", newResp.Status) - case ethservice.BlockChain().CurrentBlock().Number.Uint64() != block.NumberU64()-1: - t.Fatalf("Chain head shouldn't be updated") - } - - checkLogEvents(t, newLogCh, rmLogsCh, 0, 0) - - fcState := engine.ForkchoiceStateV1{ - HeadBlockHash: block.Hash(), - SafeBlockHash: block.Hash(), - FinalizedBlockHash: block.Hash(), - } - - if _, err := api.ForkchoiceUpdatedV1(fcState, nil); err != nil { - t.Fatalf("Failed to insert block: %v", err) - } - - if have, want := ethservice.BlockChain().CurrentBlock().Number.Uint64(), block.NumberU64(); have != want { - t.Fatalf("Chain head should be updated, have %d want %d", have, want) - } - - checkLogEvents(t, newLogCh, rmLogsCh, 1, 0) - - parent = block - } - - // Introduce fork chain - var ( - head = ethservice.BlockChain().CurrentBlock().Number.Uint64() - ) - - parent = preMergeBlocks[len(preMergeBlocks)-1] - for i := 0; i < 10; i++ { - execData, err := assembleBlock(api, parent.Hash(), &engine.PayloadAttributes{ - Timestamp: parent.Time() + 6, - }) - - if err != nil { - t.Fatalf("Failed to create the executable data %v", err) - } - - block, err := engine.ExecutableDataToBlock(*execData) - - if err != nil { - t.Fatalf("Failed to convert executable data to block %v", err) - } - - newResp, err := api.NewPayloadV1(*execData) - if err != nil || newResp.Status != "VALID" { - t.Fatalf("Failed to insert block: %v", err) - } - - if ethservice.BlockChain().CurrentBlock().Number.Uint64() != head { - t.Fatalf("Chain head shouldn't be updated") - } - - fcState := engine.ForkchoiceStateV1{ - HeadBlockHash: block.Hash(), - SafeBlockHash: block.Hash(), - FinalizedBlockHash: block.Hash(), - } - - if _, err := api.ForkchoiceUpdatedV1(fcState, nil); err != nil { - t.Fatalf("Failed to insert block: %v", err) - } +// func TestEth2NewBlock(t *testing.T) { +// t.Skip("ETH2 in Bor") + +// genesis, preMergeBlocks := generateMergeChain(10, false) + +// n, ethservice := startEthService(t, genesis, preMergeBlocks) +// defer n.Close() + +// var ( +// api = NewConsensusAPI(ethservice) +// parent = preMergeBlocks[len(preMergeBlocks)-1] + +// // This EVM code generates a log when the contract is created. +// logCode = common.Hex2Bytes("60606040525b7f24ec1d3ff24c2f6ff210738839dbc339cd45a5294d85c79361016243157aae7b60405180905060405180910390a15b600a8060416000396000f360606040526008565b00") +// ) +// // The event channels. +// newLogCh := make(chan []*types.Log, 10) +// rmLogsCh := make(chan core.RemovedLogsEvent, 10) + +// ethservice.BlockChain().SubscribeLogsEvent(newLogCh) +// ethservice.BlockChain().SubscribeRemovedLogsEvent(rmLogsCh) + +// for i := 0; i < 10; i++ { +// statedb, _ := ethservice.BlockChain().StateAt(parent.Root()) +// nonce := statedb.GetNonce(testAddr) +// tx, _ := types.SignTx(types.NewContractCreation(nonce, new(big.Int), 1000000, big.NewInt(2*params.InitialBaseFee), logCode), types.LatestSigner(ethservice.BlockChain().Config()), testKey) +// ethservice.TxPool().AddLocal(tx) + +// execData, err := assembleWithTransactions(api, parent.Hash(), &engine.PayloadAttributes{ +// Timestamp: parent.Time() + 5, +// }, 1) +// if err != nil { +// t.Fatalf("Failed to create the executable data %v", err) +// } + +// block, err := engine.ExecutableDataToBlock(*execData) +// if err != nil { +// t.Fatalf("Failed to convert executable data to block %v", err) +// } + +// newResp, err := api.NewPayloadV1(*execData) + +// switch { +// case err != nil: +// t.Fatalf("Failed to insert block: %v", err) +// case newResp.Status != "VALID": +// t.Fatalf("Failed to insert block: %v", newResp.Status) +// case ethservice.BlockChain().CurrentBlock().Number.Uint64() != block.NumberU64()-1: +// t.Fatalf("Chain head shouldn't be updated") +// } + +// checkLogEvents(t, newLogCh, rmLogsCh, 0, 0) + +// fcState := engine.ForkchoiceStateV1{ +// HeadBlockHash: block.Hash(), +// SafeBlockHash: block.Hash(), +// FinalizedBlockHash: block.Hash(), +// } + +// if _, err := api.ForkchoiceUpdatedV1(fcState, nil); err != nil { +// t.Fatalf("Failed to insert block: %v", err) +// } + +// if have, want := ethservice.BlockChain().CurrentBlock().Number.Uint64(), block.NumberU64(); have != want { +// t.Fatalf("Chain head should be updated, have %d want %d", have, want) +// } + +// checkLogEvents(t, newLogCh, rmLogsCh, 1, 0) + +// parent = block +// } + +// // Introduce fork chain +// var ( +// head = ethservice.BlockChain().CurrentBlock().Number.Uint64() +// ) + +// parent = preMergeBlocks[len(preMergeBlocks)-1] +// for i := 0; i < 10; i++ { +// execData, err := assembleBlock(api, parent.Hash(), &engine.PayloadAttributes{ +// Timestamp: parent.Time() + 6, +// }) + +// if err != nil { +// t.Fatalf("Failed to create the executable data %v", err) +// } + +// block, err := engine.ExecutableDataToBlock(*execData) + +// if err != nil { +// t.Fatalf("Failed to convert executable data to block %v", err) +// } + +// newResp, err := api.NewPayloadV1(*execData) +// if err != nil || newResp.Status != "VALID" { +// t.Fatalf("Failed to insert block: %v", err) +// } + +// if ethservice.BlockChain().CurrentBlock().Number.Uint64() != head { +// t.Fatalf("Chain head shouldn't be updated") +// } + +// fcState := engine.ForkchoiceStateV1{ +// HeadBlockHash: block.Hash(), +// SafeBlockHash: block.Hash(), +// FinalizedBlockHash: block.Hash(), +// } + +// if _, err := api.ForkchoiceUpdatedV1(fcState, nil); err != nil { +// t.Fatalf("Failed to insert block: %v", err) +// } + +// if ethservice.BlockChain().CurrentBlock().Number.Uint64() != block.NumberU64() { +// t.Fatalf("Chain head should be updated") +// } + +// parent, head = block, block.NumberU64() +// } +// } + +// func TestEth2DeepReorg(t *testing.T) { +// TODO (MariusVanDerWijden) TestEth2DeepReorg is currently broken, because it tries to reorg +// before the totalTerminalDifficulty threshold +/* + genesis, preMergeBlocks := generateMergeChain(core.TriesInMemory * 2, false) + n, ethservice := startEthService(t, genesis, preMergeBlocks) + defer n.Close() - if ethservice.BlockChain().CurrentBlock().Number.Uint64() != block.NumberU64() { - t.Fatalf("Chain head should be updated") + var ( + api = NewConsensusAPI(ethservice, nil) + parent = preMergeBlocks[len(preMergeBlocks)-core.TriesInMemory-1] + head = ethservice.BlockChain().CurrentBlock().Number.Uint64()() + ) + if ethservice.BlockChain().HasBlockAndState(parent.Hash(), parent.NumberU64()) { + t.Errorf("Block %d not pruned", parent.NumberU64()) } - - parent, head = block, block.NumberU64() + for i := 0; i < 10; i++ { + execData, err := api.assembleBlock(AssembleBlockParams{ + ParentHash: parent.Hash(), + Timestamp: parent.Time() + 5, + }) + if err != nil { + t.Fatalf("Failed to create the executable data %v", err) + } + block, err := ExecutableDataToBlock(ethservice.BlockChain().Config(), parent.Header(), *execData) + if err != nil { + t.Fatalf("Failed to convert executable data to block %v", err) + } + newResp, err := api.ExecutePayload(*execData) + if err != nil || newResp.Status != "VALID" { + t.Fatalf("Failed to insert block: %v", err) + } + if ethservice.BlockChain().CurrentBlock().Number.Uint64()() != head { + t.Fatalf("Chain head shouldn't be updated") + } + if err := api.setHead(block.Hash()); err != nil { + t.Fatalf("Failed to set head: %v", err) + } + if ethservice.BlockChain().CurrentBlock().Number.Uint64()() != block.NumberU64() { + t.Fatalf("Chain head should be updated") + } + parent, head = block, block.NumberU64() } -} - -func TestEth2DeepReorg(t *testing.T) { - // TODO (MariusVanDerWijden) TestEth2DeepReorg is currently broken, because it tries to reorg - // before the totalTerminalDifficulty threshold - /* - genesis, preMergeBlocks := generateMergeChain(core.TriesInMemory * 2, false) - n, ethservice := startEthService(t, genesis, preMergeBlocks) - defer n.Close() - - var ( - api = NewConsensusAPI(ethservice, nil) - parent = preMergeBlocks[len(preMergeBlocks)-core.TriesInMemory-1] - head = ethservice.BlockChain().CurrentBlock().Number.Uint64()() - ) - if ethservice.BlockChain().HasBlockAndState(parent.Hash(), parent.NumberU64()) { - t.Errorf("Block %d not pruned", parent.NumberU64()) - } - for i := 0; i < 10; i++ { - execData, err := api.assembleBlock(AssembleBlockParams{ - ParentHash: parent.Hash(), - Timestamp: parent.Time() + 5, - }) - if err != nil { - t.Fatalf("Failed to create the executable data %v", err) - } - block, err := ExecutableDataToBlock(ethservice.BlockChain().Config(), parent.Header(), *execData) - if err != nil { - t.Fatalf("Failed to convert executable data to block %v", err) - } - newResp, err := api.ExecutePayload(*execData) - if err != nil || newResp.Status != "VALID" { - t.Fatalf("Failed to insert block: %v", err) - } - if ethservice.BlockChain().CurrentBlock().Number.Uint64()() != head { - t.Fatalf("Chain head shouldn't be updated") - } - if err := api.setHead(block.Hash()); err != nil { - t.Fatalf("Failed to set head: %v", err) - } - if ethservice.BlockChain().CurrentBlock().Number.Uint64()() != block.NumberU64() { - t.Fatalf("Chain head should be updated") - } - parent, head = block, block.NumberU64() - } - */ -} +*/ +// } // startEthService creates a full node instance for testing. -func startEthService(t *testing.T, genesis *core.Genesis, blocks []*types.Block) (*node.Node, *eth.Ethereum) { - t.Helper() - - n, err := node.New(&node.Config{ - P2P: p2p.Config{ - ListenAddr: "0.0.0.0:0", - NoDiscovery: true, - MaxPeers: 25, - }}) - if err != nil { - t.Fatal("can't create node:", err) - } - - ethcfg := ðconfig.Config{Genesis: genesis, Ethash: ethash.Config{PowMode: ethash.ModeFake}, SyncMode: downloader.FullSync, TrieTimeout: time.Minute, TrieDirtyCache: 256, TrieCleanCache: 256} - - ethservice, err := eth.New(n, ethcfg) - if err != nil { - t.Fatal("can't create eth service:", err) - } - - if err := n.Start(); err != nil { - t.Fatal("can't start node:", err) - } - - if _, err := ethservice.BlockChain().InsertChain(blocks); err != nil { - n.Close() - t.Fatal("can't import test blocks:", err) - } - - ethservice.SetEtherbase(testAddr) - ethservice.SetSynced() - - return n, ethservice -} - -func TestFullAPI(t *testing.T) { - genesis, preMergeBlocks := generateMergeChain(10, false) - - n, ethservice := startEthService(t, genesis, preMergeBlocks) - defer n.Close() - - var ( - parent = ethservice.BlockChain().CurrentBlock() - // This EVM code generates a log when the contract is created. - logCode = common.Hex2Bytes("60606040525b7f24ec1d3ff24c2f6ff210738839dbc339cd45a5294d85c79361016243157aae7b60405180905060405180910390a15b600a8060416000396000f360606040526008565b00") - ) - - callback := func(parent *types.Header) { - statedb, _ := ethservice.BlockChain().StateAt(parent.Root) - nonce := statedb.GetNonce(testAddr) - tx, _ := types.SignTx(types.NewContractCreation(nonce, new(big.Int), 1000000, big.NewInt(2*params.InitialBaseFee), logCode), types.LatestSigner(ethservice.BlockChain().Config()), testKey) - ethservice.TxPool().AddLocal(tx) - } - - setupBlocks(t, ethservice, 10, parent, callback, nil) -} +// func startEthService(t *testing.T, genesis *core.Genesis, blocks []*types.Block) (*node.Node, *eth.Ethereum) { +// t.Helper() + +// n, err := node.New(&node.Config{ +// P2P: p2p.Config{ +// ListenAddr: "0.0.0.0:0", +// NoDiscovery: true, +// MaxPeers: 25, +// }}) +// if err != nil { +// t.Fatal("can't create node:", err) +// } + +// ethcfg := ðconfig.Config{Genesis: genesis, Ethash: ethash.Config{PowMode: ethash.ModeFake}, SyncMode: downloader.FullSync, TrieTimeout: time.Minute, TrieDirtyCache: 256, TrieCleanCache: 256} + +// ethservice, err := eth.New(n, ethcfg) +// if err != nil { +// t.Fatal("can't create eth service:", err) +// } + +// if err := n.Start(); err != nil { +// t.Fatal("can't start node:", err) +// } + +// if _, err := ethservice.BlockChain().InsertChain(blocks); err != nil { +// n.Close() +// t.Fatal("can't import test blocks:", err) +// } + +// ethservice.SetEtherbase(testAddr) +// ethservice.SetSynced() + +// return n, ethservice +// } + +// func TestFullAPI(t *testing.T) { +// genesis, preMergeBlocks := generateMergeChain(10, false) + +// n, ethservice := startEthService(t, genesis, preMergeBlocks) +// defer n.Close() + +// var ( +// parent = ethservice.BlockChain().CurrentBlock() +// // This EVM code generates a log when the contract is created. +// logCode = common.Hex2Bytes("60606040525b7f24ec1d3ff24c2f6ff210738839dbc339cd45a5294d85c79361016243157aae7b60405180905060405180910390a15b600a8060416000396000f360606040526008565b00") +// ) + +// callback := func(parent *types.Header) { +// statedb, _ := ethservice.BlockChain().StateAt(parent.Root) +// nonce := statedb.GetNonce(testAddr) +// tx, _ := types.SignTx(types.NewContractCreation(nonce, new(big.Int), 1000000, big.NewInt(2*params.InitialBaseFee), logCode), types.LatestSigner(ethservice.BlockChain().Config()), testKey) +// ethservice.TxPool().AddLocal(tx) +// } + +// setupBlocks(t, ethservice, 10, parent, callback, nil) +// } // nolint:unparam,prealloc -func setupBlocks(t *testing.T, ethservice *eth.Ethereum, n int, parent *types.Header, callback func(parent *types.Header), withdrawals [][]*types.Withdrawal) []*types.Header { - t.Helper() - - api := NewConsensusAPI(ethservice) - - var blocks []*types.Header - - for i := 0; i < n; i++ { - callback(parent) - - var w []*types.Withdrawal - - if withdrawals != nil { - w = withdrawals[i] - } - - payload := getNewPayload(t, api, parent, w) - execResp, err := api.NewPayloadV2(*payload) - - if err != nil { - t.Fatalf("can't execute payload: %v", err) - } - - if execResp.Status != engine.VALID { - t.Fatalf("invalid status: %v", execResp.Status) - } - - fcState := engine.ForkchoiceStateV1{ - HeadBlockHash: payload.BlockHash, - SafeBlockHash: payload.ParentHash, - FinalizedBlockHash: payload.ParentHash, - } - - if _, err := api.ForkchoiceUpdatedV1(fcState, nil); err != nil { - t.Fatalf("Failed to insert block: %v", err) - } - - if ethservice.BlockChain().CurrentBlock().Number.Uint64() != payload.Number { - t.Fatal("Chain head should be updated") - } - - if ethservice.BlockChain().CurrentFinalBlock().Number.Uint64() != payload.Number-1 { - t.Fatal("Finalized block should be updated") - } - - parent = ethservice.BlockChain().CurrentBlock() - blocks = append(blocks, parent) - } - - return blocks -} - -func TestExchangeTransitionConfig(t *testing.T) { - genesis, preMergeBlocks := generateMergeChain(10, false) - - n, ethservice := startEthService(t, genesis, preMergeBlocks) - defer n.Close() - - // invalid ttd - api := NewConsensusAPI(ethservice) - config := engine.TransitionConfigurationV1{ - TerminalTotalDifficulty: (*hexutil.Big)(big.NewInt(0)), - TerminalBlockHash: common.Hash{}, - TerminalBlockNumber: 0, - } - - if _, err := api.ExchangeTransitionConfigurationV1(config); err == nil { - t.Fatal("expected error on invalid config, invalid ttd") - } - // invalid terminal block hash - config = engine.TransitionConfigurationV1{ - TerminalTotalDifficulty: (*hexutil.Big)(genesis.Config.TerminalTotalDifficulty), - TerminalBlockHash: common.Hash{1}, - TerminalBlockNumber: 0, - } - if _, err := api.ExchangeTransitionConfigurationV1(config); err == nil { - t.Fatal("expected error on invalid config, invalid hash") - } - // valid config - config = engine.TransitionConfigurationV1{ - TerminalTotalDifficulty: (*hexutil.Big)(genesis.Config.TerminalTotalDifficulty), - TerminalBlockHash: common.Hash{}, - TerminalBlockNumber: 0, - } - if _, err := api.ExchangeTransitionConfigurationV1(config); err != nil { - t.Fatalf("expected no error on valid config, got %v", err) - } - // valid config - config = engine.TransitionConfigurationV1{ - TerminalTotalDifficulty: (*hexutil.Big)(genesis.Config.TerminalTotalDifficulty), - TerminalBlockHash: preMergeBlocks[5].Hash(), - TerminalBlockNumber: 6, - } - if _, err := api.ExchangeTransitionConfigurationV1(config); err != nil { - t.Fatalf("expected no error on valid config, got %v", err) - } -} +// func setupBlocks(t *testing.T, ethservice *eth.Ethereum, n int, parent *types.Header, callback func(parent *types.Header), withdrawals [][]*types.Withdrawal) []*types.Header { +// t.Helper() + +// api := NewConsensusAPI(ethservice) + +// var blocks []*types.Header + +// for i := 0; i < n; i++ { +// callback(parent) + +// var w []*types.Withdrawal + +// if withdrawals != nil { +// w = withdrawals[i] +// } + +// payload := getNewPayload(t, api, parent, w) +// execResp, err := api.NewPayloadV2(*payload) + +// if err != nil { +// t.Fatalf("can't execute payload: %v", err) +// } + +// if execResp.Status != engine.VALID { +// t.Fatalf("invalid status: %v", execResp.Status) +// } + +// fcState := engine.ForkchoiceStateV1{ +// HeadBlockHash: payload.BlockHash, +// SafeBlockHash: payload.ParentHash, +// FinalizedBlockHash: payload.ParentHash, +// } + +// if _, err := api.ForkchoiceUpdatedV1(fcState, nil); err != nil { +// t.Fatalf("Failed to insert block: %v", err) +// } + +// if ethservice.BlockChain().CurrentBlock().Number.Uint64() != payload.Number { +// t.Fatal("Chain head should be updated") +// } + +// if ethservice.BlockChain().CurrentFinalBlock().Number.Uint64() != payload.Number-1 { +// t.Fatal("Finalized block should be updated") +// } + +// parent = ethservice.BlockChain().CurrentBlock() +// blocks = append(blocks, parent) +// } + +// return blocks +// } + +// func TestExchangeTransitionConfig(t *testing.T) { +// genesis, preMergeBlocks := generateMergeChain(10, false) + +// n, ethservice := startEthService(t, genesis, preMergeBlocks) +// defer n.Close() + +// // invalid ttd +// api := NewConsensusAPI(ethservice) +// config := engine.TransitionConfigurationV1{ +// TerminalTotalDifficulty: (*hexutil.Big)(big.NewInt(0)), +// TerminalBlockHash: common.Hash{}, +// TerminalBlockNumber: 0, +// } + +// if _, err := api.ExchangeTransitionConfigurationV1(config); err == nil { +// t.Fatal("expected error on invalid config, invalid ttd") +// } +// // invalid terminal block hash +// config = engine.TransitionConfigurationV1{ +// TerminalTotalDifficulty: (*hexutil.Big)(genesis.Config.TerminalTotalDifficulty), +// TerminalBlockHash: common.Hash{1}, +// TerminalBlockNumber: 0, +// } +// if _, err := api.ExchangeTransitionConfigurationV1(config); err == nil { +// t.Fatal("expected error on invalid config, invalid hash") +// } +// // valid config +// config = engine.TransitionConfigurationV1{ +// TerminalTotalDifficulty: (*hexutil.Big)(genesis.Config.TerminalTotalDifficulty), +// TerminalBlockHash: common.Hash{}, +// TerminalBlockNumber: 0, +// } +// if _, err := api.ExchangeTransitionConfigurationV1(config); err != nil { +// t.Fatalf("expected no error on valid config, got %v", err) +// } +// // valid config +// config = engine.TransitionConfigurationV1{ +// TerminalTotalDifficulty: (*hexutil.Big)(genesis.Config.TerminalTotalDifficulty), +// TerminalBlockHash: preMergeBlocks[5].Hash(), +// TerminalBlockNumber: 6, +// } +// if _, err := api.ExchangeTransitionConfigurationV1(config); err != nil { +// t.Fatalf("expected no error on valid config, got %v", err) +// } +// } /* TestNewPayloadOnInvalidChain sets up a valid chain and tries to feed blocks @@ -656,1058 +624,1058 @@ We expect │ └── P1'' */ -func TestNewPayloadOnInvalidChain(t *testing.T) { - t.Parallel() - - genesis, preMergeBlocks := generateMergeChain(10, false) - n, ethservice := startEthService(t, genesis, preMergeBlocks) - - defer n.Close() - - var ( - api = NewConsensusAPI(ethservice) - parent = ethservice.BlockChain().CurrentBlock() - signer = types.LatestSigner(ethservice.BlockChain().Config()) - // This EVM code generates a log when the contract is created. - logCode = common.Hex2Bytes("60606040525b7f24ec1d3ff24c2f6ff210738839dbc339cd45a5294d85c79361016243157aae7b60405180905060405180910390a15b600a8060416000396000f360606040526008565b00") - ) - - for i := 0; i < 10; i++ { - statedb, _ := ethservice.BlockChain().StateAt(parent.Root) - tx := types.MustSignNewTx(testKey, signer, &types.LegacyTx{ - Nonce: statedb.GetNonce(testAddr), - Value: new(big.Int), - Gas: 1000000, - GasPrice: big.NewInt(2 * params.InitialBaseFee), - Data: logCode, - }) - ethservice.TxPool().AddRemotesSync([]*types.Transaction{tx}) - - var ( - params = engine.PayloadAttributes{ - Timestamp: parent.Time + 1, - Random: crypto.Keccak256Hash([]byte{byte(i)}), - SuggestedFeeRecipient: parent.Coinbase, - } - fcState = engine.ForkchoiceStateV1{ - HeadBlockHash: parent.Hash(), - SafeBlockHash: common.Hash{}, - FinalizedBlockHash: common.Hash{}, - } - payload *engine.ExecutableData - resp engine.ForkChoiceResponse - err error - ) - - for i := 0; ; i++ { - if resp, err = api.ForkchoiceUpdatedV1(fcState, ¶ms); err != nil { - t.Fatalf("error preparing payload, err=%v", err) - } - - if resp.PayloadStatus.Status != engine.VALID { - t.Fatalf("error preparing payload, invalid status: %v", resp.PayloadStatus.Status) - } - - // give the payload some time to be built - time.Sleep(50 * time.Millisecond) - - if payload, err = api.GetPayloadV1(*resp.PayloadID); err != nil { - t.Fatalf("can't get payload: %v", err) - } - - if len(payload.Transactions) > 0 { - break - } - - // No luck this time we need to update the params and try again. - params.Timestamp = params.Timestamp + 1 - - if i > 10 { - t.Fatalf("payload should not be empty") - } - } - - execResp, err := api.NewPayloadV1(*payload) - - if err != nil { - t.Fatalf("can't execute payload: %v", err) - } - - if execResp.Status != engine.VALID { - t.Fatalf("invalid status: %v", execResp.Status) - } - - fcState = engine.ForkchoiceStateV1{ - HeadBlockHash: payload.BlockHash, - SafeBlockHash: payload.ParentHash, - FinalizedBlockHash: payload.ParentHash, - } - - if _, err := api.ForkchoiceUpdatedV1(fcState, nil); err != nil { - t.Fatalf("Failed to insert block: %v", err) - } - - if ethservice.BlockChain().CurrentBlock().Number.Uint64() != payload.Number { - t.Fatalf("Chain head should be updated") - } - - parent = ethservice.BlockChain().CurrentBlock() - } -} - -func assembleBlock(api *ConsensusAPI, parentHash common.Hash, params *engine.PayloadAttributes) (*engine.ExecutableData, error) { - args := &miner.BuildPayloadArgs{ - Parent: parentHash, - Timestamp: params.Timestamp, - FeeRecipient: params.SuggestedFeeRecipient, - Random: params.Random, - Withdrawals: params.Withdrawals, - } - payload, err := api.eth.Miner().BuildPayload(args) - - if err != nil { - return nil, err - } - - return payload.ResolveFull().ExecutionPayload, nil -} - -func TestEmptyBlocks(t *testing.T) { - t.Parallel() - - genesis, preMergeBlocks := generateMergeChain(10, false) - n, ethservice := startEthService(t, genesis, preMergeBlocks) - - defer n.Close() - - commonAncestor := ethservice.BlockChain().CurrentBlock() - api := NewConsensusAPI(ethservice) - - // Setup 10 blocks on the canonical chain - setupBlocks(t, ethservice, 10, commonAncestor, func(parent *types.Header) {}, nil) - - // (1) check LatestValidHash by sending a normal payload (P1'') - payload := getNewPayload(t, api, commonAncestor, nil) - - status, err := api.NewPayloadV1(*payload) - if err != nil { - t.Fatal(err) - } - - if status.Status != engine.VALID { - t.Errorf("invalid status: expected VALID got: %v", status.Status) - } - - if !bytes.Equal(status.LatestValidHash[:], payload.BlockHash[:]) { - t.Fatalf("invalid LVH: got %v want %v", status.LatestValidHash, payload.BlockHash) - } - - // (2) Now send P1' which is invalid - payload = getNewPayload(t, api, commonAncestor, nil) - payload.GasUsed += 1 - payload = setBlockhash(payload) - // Now latestValidHash should be the common ancestor - status, err = api.NewPayloadV1(*payload) - if err != nil { - t.Fatal(err) - } - - if status.Status != engine.INVALID { - t.Errorf("invalid status: expected INVALID got: %v", status.Status) - } - // Expect 0x0 on INVALID block on top of PoW block - expected := common.Hash{} - if !bytes.Equal(status.LatestValidHash[:], expected[:]) { - t.Fatalf("invalid LVH: got %v want %v", status.LatestValidHash, expected) - } - - // (3) Now send a payload with unknown parent - payload = getNewPayload(t, api, commonAncestor, nil) - payload.ParentHash = common.Hash{1} - payload = setBlockhash(payload) - // Now latestValidHash should be the common ancestor - status, err = api.NewPayloadV1(*payload) - if err != nil { - t.Fatal(err) - } - - if status.Status != engine.SYNCING { - t.Errorf("invalid status: expected SYNCING got: %v", status.Status) - } - - if status.LatestValidHash != nil { - t.Fatalf("invalid LVH: got %v wanted nil", status.LatestValidHash) - } -} - -func getNewPayload(t *testing.T, api *ConsensusAPI, parent *types.Header, withdrawals []*types.Withdrawal) *engine.ExecutableData { - t.Helper() - - params := engine.PayloadAttributes{ - Timestamp: parent.Time + 1, - Random: crypto.Keccak256Hash([]byte{byte(1)}), - SuggestedFeeRecipient: parent.Coinbase, - Withdrawals: withdrawals, - } - - payload, err := assembleBlock(api, parent.Hash(), ¶ms) - if err != nil { - t.Fatal(err) - } - - return payload -} +// func TestNewPayloadOnInvalidChain(t *testing.T) { +// t.Parallel() + +// genesis, preMergeBlocks := generateMergeChain(10, false) +// n, ethservice := startEthService(t, genesis, preMergeBlocks) + +// defer n.Close() + +// var ( +// api = NewConsensusAPI(ethservice) +// parent = ethservice.BlockChain().CurrentBlock() +// signer = types.LatestSigner(ethservice.BlockChain().Config()) +// // This EVM code generates a log when the contract is created. +// logCode = common.Hex2Bytes("60606040525b7f24ec1d3ff24c2f6ff210738839dbc339cd45a5294d85c79361016243157aae7b60405180905060405180910390a15b600a8060416000396000f360606040526008565b00") +// ) + +// for i := 0; i < 10; i++ { +// statedb, _ := ethservice.BlockChain().StateAt(parent.Root) +// tx := types.MustSignNewTx(testKey, signer, &types.LegacyTx{ +// Nonce: statedb.GetNonce(testAddr), +// Value: new(big.Int), +// Gas: 1000000, +// GasPrice: big.NewInt(2 * params.InitialBaseFee), +// Data: logCode, +// }) +// ethservice.TxPool().AddRemotesSync([]*types.Transaction{tx}) + +// var ( +// params = engine.PayloadAttributes{ +// Timestamp: parent.Time + 1, +// Random: crypto.Keccak256Hash([]byte{byte(i)}), +// SuggestedFeeRecipient: parent.Coinbase, +// } +// fcState = engine.ForkchoiceStateV1{ +// HeadBlockHash: parent.Hash(), +// SafeBlockHash: common.Hash{}, +// FinalizedBlockHash: common.Hash{}, +// } +// payload *engine.ExecutableData +// resp engine.ForkChoiceResponse +// err error +// ) + +// for i := 0; ; i++ { +// if resp, err = api.ForkchoiceUpdatedV1(fcState, ¶ms); err != nil { +// t.Fatalf("error preparing payload, err=%v", err) +// } + +// if resp.PayloadStatus.Status != engine.VALID { +// t.Fatalf("error preparing payload, invalid status: %v", resp.PayloadStatus.Status) +// } + +// // give the payload some time to be built +// time.Sleep(50 * time.Millisecond) + +// if payload, err = api.GetPayloadV1(*resp.PayloadID); err != nil { +// t.Fatalf("can't get payload: %v", err) +// } + +// if len(payload.Transactions) > 0 { +// break +// } + +// // No luck this time we need to update the params and try again. +// params.Timestamp = params.Timestamp + 1 + +// if i > 10 { +// t.Fatalf("payload should not be empty") +// } +// } + +// execResp, err := api.NewPayloadV1(*payload) + +// if err != nil { +// t.Fatalf("can't execute payload: %v", err) +// } + +// if execResp.Status != engine.VALID { +// t.Fatalf("invalid status: %v", execResp.Status) +// } + +// fcState = engine.ForkchoiceStateV1{ +// HeadBlockHash: payload.BlockHash, +// SafeBlockHash: payload.ParentHash, +// FinalizedBlockHash: payload.ParentHash, +// } + +// if _, err := api.ForkchoiceUpdatedV1(fcState, nil); err != nil { +// t.Fatalf("Failed to insert block: %v", err) +// } + +// if ethservice.BlockChain().CurrentBlock().Number.Uint64() != payload.Number { +// t.Fatalf("Chain head should be updated") +// } + +// parent = ethservice.BlockChain().CurrentBlock() +// } +// } + +// func assembleBlock(api *ConsensusAPI, parentHash common.Hash, params *engine.PayloadAttributes) (*engine.ExecutableData, error) { +// args := &miner.BuildPayloadArgs{ +// Parent: parentHash, +// Timestamp: params.Timestamp, +// FeeRecipient: params.SuggestedFeeRecipient, +// Random: params.Random, +// Withdrawals: params.Withdrawals, +// } +// payload, err := api.eth.Miner().BuildPayload(args) + +// if err != nil { +// return nil, err +// } + +// return payload.ResolveFull().ExecutionPayload, nil +// } + +// func TestEmptyBlocks(t *testing.T) { +// t.Parallel() + +// genesis, preMergeBlocks := generateMergeChain(10, false) +// n, ethservice := startEthService(t, genesis, preMergeBlocks) + +// defer n.Close() + +// commonAncestor := ethservice.BlockChain().CurrentBlock() +// api := NewConsensusAPI(ethservice) + +// // Setup 10 blocks on the canonical chain +// setupBlocks(t, ethservice, 10, commonAncestor, func(parent *types.Header) {}, nil) + +// // (1) check LatestValidHash by sending a normal payload (P1'') +// payload := getNewPayload(t, api, commonAncestor, nil) + +// status, err := api.NewPayloadV1(*payload) +// if err != nil { +// t.Fatal(err) +// } + +// if status.Status != engine.VALID { +// t.Errorf("invalid status: expected VALID got: %v", status.Status) +// } + +// if !bytes.Equal(status.LatestValidHash[:], payload.BlockHash[:]) { +// t.Fatalf("invalid LVH: got %v want %v", status.LatestValidHash, payload.BlockHash) +// } + +// // (2) Now send P1' which is invalid +// payload = getNewPayload(t, api, commonAncestor, nil) +// payload.GasUsed += 1 +// payload = setBlockhash(payload) +// // Now latestValidHash should be the common ancestor +// status, err = api.NewPayloadV1(*payload) +// if err != nil { +// t.Fatal(err) +// } + +// if status.Status != engine.INVALID { +// t.Errorf("invalid status: expected INVALID got: %v", status.Status) +// } +// // Expect 0x0 on INVALID block on top of PoW block +// expected := common.Hash{} +// if !bytes.Equal(status.LatestValidHash[:], expected[:]) { +// t.Fatalf("invalid LVH: got %v want %v", status.LatestValidHash, expected) +// } + +// // (3) Now send a payload with unknown parent +// payload = getNewPayload(t, api, commonAncestor, nil) +// payload.ParentHash = common.Hash{1} +// payload = setBlockhash(payload) +// // Now latestValidHash should be the common ancestor +// status, err = api.NewPayloadV1(*payload) +// if err != nil { +// t.Fatal(err) +// } + +// if status.Status != engine.SYNCING { +// t.Errorf("invalid status: expected SYNCING got: %v", status.Status) +// } + +// if status.LatestValidHash != nil { +// t.Fatalf("invalid LVH: got %v wanted nil", status.LatestValidHash) +// } +// } + +// func getNewPayload(t *testing.T, api *ConsensusAPI, parent *types.Header, withdrawals []*types.Withdrawal) *engine.ExecutableData { +// t.Helper() + +// params := engine.PayloadAttributes{ +// Timestamp: parent.Time + 1, +// Random: crypto.Keccak256Hash([]byte{byte(1)}), +// SuggestedFeeRecipient: parent.Coinbase, +// Withdrawals: withdrawals, +// } + +// payload, err := assembleBlock(api, parent.Hash(), ¶ms) +// if err != nil { +// t.Fatal(err) +// } + +// return payload +// } // setBlockhash sets the blockhash of a modified ExecutableData. // Can be used to make modified payloads look valid. -func setBlockhash(data *engine.ExecutableData) *engine.ExecutableData { - txs, _ := decodeTransactions(data.Transactions) - number := big.NewInt(0) - number.SetUint64(data.Number) - - header := &types.Header{ - ParentHash: data.ParentHash, - UncleHash: types.EmptyUncleHash, - Coinbase: data.FeeRecipient, - Root: data.StateRoot, - TxHash: types.DeriveSha(types.Transactions(txs), trie.NewStackTrie(nil)), - ReceiptHash: data.ReceiptsRoot, - Bloom: types.BytesToBloom(data.LogsBloom), - Difficulty: common.Big0, - Number: number, - GasLimit: data.GasLimit, - GasUsed: data.GasUsed, - Time: data.Timestamp, - BaseFee: data.BaseFeePerGas, - Extra: data.ExtraData, - MixDigest: data.Random, - } - block := types.NewBlockWithHeader(header).WithBody(txs, nil /* uncles */) - data.BlockHash = block.Hash() - - return data -} - -func decodeTransactions(enc [][]byte) ([]*types.Transaction, error) { - var txs = make([]*types.Transaction, len(enc)) - - for i, encTx := range enc { - var tx types.Transaction - if err := tx.UnmarshalBinary(encTx); err != nil { - return nil, fmt.Errorf("invalid transaction %d: %v", i, err) - } - - txs[i] = &tx - } - - return txs, nil -} - -func TestTrickRemoteBlockCache(t *testing.T) { - t.Parallel() - - // Setup two nodes - genesis, preMergeBlocks := generateMergeChain(10, false) - nodeA, ethserviceA := startEthService(t, genesis, preMergeBlocks) - nodeB, ethserviceB := startEthService(t, genesis, preMergeBlocks) - - defer nodeA.Close() - defer nodeB.Close() - - for nodeB.Server().NodeInfo().Ports.Listener == 0 { - time.Sleep(250 * time.Millisecond) - } - nodeA.Server().AddPeer(nodeB.Server().Self()) - nodeB.Server().AddPeer(nodeA.Server().Self()) - - apiA := NewConsensusAPI(ethserviceA) - apiB := NewConsensusAPI(ethserviceB) - - commonAncestor := ethserviceA.BlockChain().CurrentBlock() - - // Setup 10 blocks on the canonical chain - setupBlocks(t, ethserviceA, 10, commonAncestor, func(parent *types.Header) {}, nil) - commonAncestor = ethserviceA.BlockChain().CurrentBlock() - - // nolint:prealloc - var invalidChain []*engine.ExecutableData - // create a valid payload (P1) - //payload1 := getNewPayload(t, apiA, commonAncestor) - //invalidChain = append(invalidChain, payload1) - - // create an invalid payload2 (P2) - payload2 := getNewPayload(t, apiA, commonAncestor, nil) - //payload2.ParentHash = payload1.BlockHash - payload2.GasUsed += 1 - payload2 = setBlockhash(payload2) - invalidChain = append(invalidChain, payload2) - - head := payload2 - // create some valid payloads on top - for i := 0; i < 10; i++ { - payload := getNewPayload(t, apiA, commonAncestor, nil) - payload.ParentHash = head.BlockHash - payload = setBlockhash(payload) - invalidChain = append(invalidChain, payload) - head = payload - } - - // feed the payloads to node B - for _, payload := range invalidChain { - status, err := apiB.NewPayloadV1(*payload) - if err != nil { - panic(err) - } - - if status.Status == engine.VALID { - t.Error("invalid status: VALID on an invalid chain") - } - // Now reorg to the head of the invalid chain - resp, err := apiB.ForkchoiceUpdatedV1(engine.ForkchoiceStateV1{HeadBlockHash: payload.BlockHash, SafeBlockHash: payload.BlockHash, FinalizedBlockHash: payload.ParentHash}, nil) - if err != nil { - t.Fatal(err) - } - - if resp.PayloadStatus.Status == engine.VALID { - t.Error("invalid status: VALID on an invalid chain") - } - - time.Sleep(100 * time.Millisecond) - } -} - -func TestInvalidBloom(t *testing.T) { - t.Parallel() - - genesis, preMergeBlocks := generateMergeChain(10, false) - n, ethservice := startEthService(t, genesis, preMergeBlocks) - ethservice.Merger().ReachTTD() - - defer n.Close() - - commonAncestor := ethservice.BlockChain().CurrentBlock() - api := NewConsensusAPI(ethservice) - - // Setup 10 blocks on the canonical chain - setupBlocks(t, ethservice, 10, commonAncestor, func(parent *types.Header) {}, nil) - - // (1) check LatestValidHash by sending a normal payload (P1'') - payload := getNewPayload(t, api, commonAncestor, nil) - payload.LogsBloom = append(payload.LogsBloom, byte(1)) - status, err := api.NewPayloadV1(*payload) - - if err != nil { - t.Fatal(err) - } - - if status.Status != engine.INVALID { - t.Errorf("invalid status: expected INVALID got: %v", status.Status) - } -} - -func TestNewPayloadOnInvalidTerminalBlock(t *testing.T) { - t.Parallel() - - genesis, preMergeBlocks := generateMergeChain(100, false) - n, ethservice := startEthService(t, genesis, preMergeBlocks) - - defer n.Close() - - api := NewConsensusAPI(ethservice) - - // Test parent already post TTD in FCU - parent := preMergeBlocks[len(preMergeBlocks)-2] - fcState := engine.ForkchoiceStateV1{ - HeadBlockHash: parent.Hash(), - SafeBlockHash: common.Hash{}, - FinalizedBlockHash: common.Hash{}, - } - resp, err := api.ForkchoiceUpdatedV1(fcState, nil) - - if err != nil { - t.Fatalf("error sending forkchoice, err=%v", err) - } - - if resp.PayloadStatus != engine.INVALID_TERMINAL_BLOCK { - t.Fatalf("error sending invalid forkchoice, invalid status: %v", resp.PayloadStatus.Status) - } - - // Test parent already post TTD in NewPayload - args := &miner.BuildPayloadArgs{ - Parent: parent.Hash(), - Timestamp: parent.Time() + 1, - Random: crypto.Keccak256Hash([]byte{byte(1)}), - FeeRecipient: parent.Coinbase(), - } - payload, err := api.eth.Miner().BuildPayload(args) - - if err != nil { - t.Fatalf("error preparing payload, err=%v", err) - } - - data := *payload.Resolve().ExecutionPayload - // We need to recompute the blockhash, since the miner computes a wrong (correct) blockhash - txs, _ := decodeTransactions(data.Transactions) - header := &types.Header{ - ParentHash: data.ParentHash, - UncleHash: types.EmptyUncleHash, - Coinbase: data.FeeRecipient, - Root: data.StateRoot, - TxHash: types.DeriveSha(types.Transactions(txs), trie.NewStackTrie(nil)), - ReceiptHash: data.ReceiptsRoot, - Bloom: types.BytesToBloom(data.LogsBloom), - Difficulty: common.Big0, - Number: new(big.Int).SetUint64(data.Number), - GasLimit: data.GasLimit, - GasUsed: data.GasUsed, - Time: data.Timestamp, - BaseFee: data.BaseFeePerGas, - Extra: data.ExtraData, - MixDigest: data.Random, - } - block := types.NewBlockWithHeader(header).WithBody(txs, nil /* uncles */) - data.BlockHash = block.Hash() - // Send the new payload - resp2, err := api.NewPayloadV1(data) - if err != nil { - t.Fatalf("error sending NewPayload, err=%v", err) - } - - if resp2 != engine.INVALID_TERMINAL_BLOCK { - t.Fatalf("error sending invalid forkchoice, invalid status: %v", resp.PayloadStatus.Status) - } -} - -// TestSimultaneousNewBlock does several parallel inserts, both as -// newPayLoad and forkchoiceUpdate. This is to test that the api behaves -// well even of the caller is not being 'serial'. -func TestSimultaneousNewBlock(t *testing.T) { - t.Parallel() - - genesis, preMergeBlocks := generateMergeChain(10, false) - n, ethservice := startEthService(t, genesis, preMergeBlocks) - - defer n.Close() - - var ( - api = NewConsensusAPI(ethservice) - parent = preMergeBlocks[len(preMergeBlocks)-1] - ) - - for i := 0; i < 10; i++ { - execData, err := assembleBlock(api, parent.Hash(), &engine.PayloadAttributes{ - Timestamp: parent.Time() + 5, - }) - if err != nil { - t.Fatalf("Failed to create the executable data %v", err) - } - // Insert it 10 times in parallel. Should be ignored. - { - var ( - wg sync.WaitGroup - testErr error - errMu sync.Mutex - ) - - wg.Add(10) - - for ii := 0; ii < 10; ii++ { - go func() { - defer wg.Done() - - if newResp, err := api.NewPayloadV1(*execData); err != nil { - errMu.Lock() - testErr = fmt.Errorf("Failed to insert block: %w", err) - errMu.Unlock() - } else if newResp.Status != "VALID" { - errMu.Lock() - testErr = fmt.Errorf("Failed to insert block: %v", newResp.Status) - errMu.Unlock() - } - }() - } - wg.Wait() - - if testErr != nil { - t.Fatal(testErr) - } - } - - block, err := engine.ExecutableDataToBlock(*execData) - - if err != nil { - t.Fatalf("Failed to convert executable data to block %v", err) - } - - if ethservice.BlockChain().CurrentBlock().Number.Uint64() != block.NumberU64()-1 { - t.Fatalf("Chain head shouldn't be updated") - } - - fcState := engine.ForkchoiceStateV1{ - HeadBlockHash: block.Hash(), - SafeBlockHash: block.Hash(), - FinalizedBlockHash: block.Hash(), - } - { - var ( - wg sync.WaitGroup - testErr error - errMu sync.Mutex - ) - - wg.Add(10) - // Do each FCU 10 times - for ii := 0; ii < 10; ii++ { - go func() { - defer wg.Done() - - if _, err := api.ForkchoiceUpdatedV1(fcState, nil); err != nil { - errMu.Lock() - testErr = fmt.Errorf("Failed to insert block: %w", err) - errMu.Unlock() - } - }() - } - wg.Wait() - - if testErr != nil { - t.Fatal(testErr) - } - } - - if have, want := ethservice.BlockChain().CurrentBlock().Number.Uint64(), block.NumberU64(); have != want { - t.Fatalf("Chain head should be updated, have %d want %d", have, want) - } - - parent = block - } -} +// func setBlockhash(data *engine.ExecutableData) *engine.ExecutableData { +// txs, _ := decodeTransactions(data.Transactions) +// number := big.NewInt(0) +// number.SetUint64(data.Number) + +// header := &types.Header{ +// ParentHash: data.ParentHash, +// UncleHash: types.EmptyUncleHash, +// Coinbase: data.FeeRecipient, +// Root: data.StateRoot, +// TxHash: types.DeriveSha(types.Transactions(txs), trie.NewStackTrie(nil)), +// ReceiptHash: data.ReceiptsRoot, +// Bloom: types.BytesToBloom(data.LogsBloom), +// Difficulty: common.Big0, +// Number: number, +// GasLimit: data.GasLimit, +// GasUsed: data.GasUsed, +// Time: data.Timestamp, +// BaseFee: data.BaseFeePerGas, +// Extra: data.ExtraData, +// MixDigest: data.Random, +// } +// block := types.NewBlockWithHeader(header).WithBody(txs, nil /* uncles */) +// data.BlockHash = block.Hash() + +// return data +// } + +// func decodeTransactions(enc [][]byte) ([]*types.Transaction, error) { +// var txs = make([]*types.Transaction, len(enc)) + +// for i, encTx := range enc { +// var tx types.Transaction +// if err := tx.UnmarshalBinary(encTx); err != nil { +// return nil, fmt.Errorf("invalid transaction %d: %v", i, err) +// } + +// txs[i] = &tx +// } + +// return txs, nil +// } + +// func TestTrickRemoteBlockCache(t *testing.T) { +// t.Parallel() + +// // Setup two nodes +// genesis, preMergeBlocks := generateMergeChain(10, false) +// nodeA, ethserviceA := startEthService(t, genesis, preMergeBlocks) +// nodeB, ethserviceB := startEthService(t, genesis, preMergeBlocks) + +// defer nodeA.Close() +// defer nodeB.Close() + +// for nodeB.Server().NodeInfo().Ports.Listener == 0 { +// time.Sleep(250 * time.Millisecond) +// } +// nodeA.Server().AddPeer(nodeB.Server().Self()) +// nodeB.Server().AddPeer(nodeA.Server().Self()) + +// apiA := NewConsensusAPI(ethserviceA) +// apiB := NewConsensusAPI(ethserviceB) + +// commonAncestor := ethserviceA.BlockChain().CurrentBlock() + +// // Setup 10 blocks on the canonical chain +// setupBlocks(t, ethserviceA, 10, commonAncestor, func(parent *types.Header) {}, nil) +// commonAncestor = ethserviceA.BlockChain().CurrentBlock() + +// // nolint:prealloc +// var invalidChain []*engine.ExecutableData +// // create a valid payload (P1) +// //payload1 := getNewPayload(t, apiA, commonAncestor) +// //invalidChain = append(invalidChain, payload1) + +// // create an invalid payload2 (P2) +// payload2 := getNewPayload(t, apiA, commonAncestor, nil) +// //payload2.ParentHash = payload1.BlockHash +// payload2.GasUsed += 1 +// payload2 = setBlockhash(payload2) +// invalidChain = append(invalidChain, payload2) + +// head := payload2 +// // create some valid payloads on top +// for i := 0; i < 10; i++ { +// payload := getNewPayload(t, apiA, commonAncestor, nil) +// payload.ParentHash = head.BlockHash +// payload = setBlockhash(payload) +// invalidChain = append(invalidChain, payload) +// head = payload +// } + +// // feed the payloads to node B +// for _, payload := range invalidChain { +// status, err := apiB.NewPayloadV1(*payload) +// if err != nil { +// panic(err) +// } + +// if status.Status == engine.VALID { +// t.Error("invalid status: VALID on an invalid chain") +// } +// // Now reorg to the head of the invalid chain +// resp, err := apiB.ForkchoiceUpdatedV1(engine.ForkchoiceStateV1{HeadBlockHash: payload.BlockHash, SafeBlockHash: payload.BlockHash, FinalizedBlockHash: payload.ParentHash}, nil) +// if err != nil { +// t.Fatal(err) +// } + +// if resp.PayloadStatus.Status == engine.VALID { +// t.Error("invalid status: VALID on an invalid chain") +// } + +// time.Sleep(100 * time.Millisecond) +// } +// } + +// func TestInvalidBloom(t *testing.T) { +// t.Parallel() + +// genesis, preMergeBlocks := generateMergeChain(10, false) +// n, ethservice := startEthService(t, genesis, preMergeBlocks) +// ethservice.Merger().ReachTTD() + +// defer n.Close() + +// commonAncestor := ethservice.BlockChain().CurrentBlock() +// api := NewConsensusAPI(ethservice) + +// // Setup 10 blocks on the canonical chain +// setupBlocks(t, ethservice, 10, commonAncestor, func(parent *types.Header) {}, nil) + +// // (1) check LatestValidHash by sending a normal payload (P1'') +// payload := getNewPayload(t, api, commonAncestor, nil) +// payload.LogsBloom = append(payload.LogsBloom, byte(1)) +// status, err := api.NewPayloadV1(*payload) + +// if err != nil { +// t.Fatal(err) +// } + +// if status.Status != engine.INVALID { +// t.Errorf("invalid status: expected INVALID got: %v", status.Status) +// } +// } + +// func TestNewPayloadOnInvalidTerminalBlock(t *testing.T) { +// t.Parallel() + +// genesis, preMergeBlocks := generateMergeChain(100, false) +// n, ethservice := startEthService(t, genesis, preMergeBlocks) + +// defer n.Close() + +// api := NewConsensusAPI(ethservice) + +// // Test parent already post TTD in FCU +// parent := preMergeBlocks[len(preMergeBlocks)-2] +// fcState := engine.ForkchoiceStateV1{ +// HeadBlockHash: parent.Hash(), +// SafeBlockHash: common.Hash{}, +// FinalizedBlockHash: common.Hash{}, +// } +// resp, err := api.ForkchoiceUpdatedV1(fcState, nil) + +// if err != nil { +// t.Fatalf("error sending forkchoice, err=%v", err) +// } + +// if resp.PayloadStatus != engine.INVALID_TERMINAL_BLOCK { +// t.Fatalf("error sending invalid forkchoice, invalid status: %v", resp.PayloadStatus.Status) +// } + +// // Test parent already post TTD in NewPayload +// args := &miner.BuildPayloadArgs{ +// Parent: parent.Hash(), +// Timestamp: parent.Time() + 1, +// Random: crypto.Keccak256Hash([]byte{byte(1)}), +// FeeRecipient: parent.Coinbase(), +// } +// payload, err := api.eth.Miner().BuildPayload(args) + +// if err != nil { +// t.Fatalf("error preparing payload, err=%v", err) +// } + +// data := *payload.Resolve().ExecutionPayload +// // We need to recompute the blockhash, since the miner computes a wrong (correct) blockhash +// txs, _ := decodeTransactions(data.Transactions) +// header := &types.Header{ +// ParentHash: data.ParentHash, +// UncleHash: types.EmptyUncleHash, +// Coinbase: data.FeeRecipient, +// Root: data.StateRoot, +// TxHash: types.DeriveSha(types.Transactions(txs), trie.NewStackTrie(nil)), +// ReceiptHash: data.ReceiptsRoot, +// Bloom: types.BytesToBloom(data.LogsBloom), +// Difficulty: common.Big0, +// Number: new(big.Int).SetUint64(data.Number), +// GasLimit: data.GasLimit, +// GasUsed: data.GasUsed, +// Time: data.Timestamp, +// BaseFee: data.BaseFeePerGas, +// Extra: data.ExtraData, +// MixDigest: data.Random, +// } +// block := types.NewBlockWithHeader(header).WithBody(txs, nil /* uncles */) +// data.BlockHash = block.Hash() +// // Send the new payload +// resp2, err := api.NewPayloadV1(data) +// if err != nil { +// t.Fatalf("error sending NewPayload, err=%v", err) +// } + +// if resp2 != engine.INVALID_TERMINAL_BLOCK { +// t.Fatalf("error sending invalid forkchoice, invalid status: %v", resp.PayloadStatus.Status) +// } +// } + +// // TestSimultaneousNewBlock does several parallel inserts, both as +// // newPayLoad and forkchoiceUpdate. This is to test that the api behaves +// // well even of the caller is not being 'serial'. +// func TestSimultaneousNewBlock(t *testing.T) { +// t.Parallel() + +// genesis, preMergeBlocks := generateMergeChain(10, false) +// n, ethservice := startEthService(t, genesis, preMergeBlocks) + +// defer n.Close() + +// var ( +// api = NewConsensusAPI(ethservice) +// parent = preMergeBlocks[len(preMergeBlocks)-1] +// ) + +// for i := 0; i < 10; i++ { +// execData, err := assembleBlock(api, parent.Hash(), &engine.PayloadAttributes{ +// Timestamp: parent.Time() + 5, +// }) +// if err != nil { +// t.Fatalf("Failed to create the executable data %v", err) +// } +// // Insert it 10 times in parallel. Should be ignored. +// { +// var ( +// wg sync.WaitGroup +// testErr error +// errMu sync.Mutex +// ) + +// wg.Add(10) + +// for ii := 0; ii < 10; ii++ { +// go func() { +// defer wg.Done() + +// if newResp, err := api.NewPayloadV1(*execData); err != nil { +// errMu.Lock() +// testErr = fmt.Errorf("Failed to insert block: %w", err) +// errMu.Unlock() +// } else if newResp.Status != "VALID" { +// errMu.Lock() +// testErr = fmt.Errorf("Failed to insert block: %v", newResp.Status) +// errMu.Unlock() +// } +// }() +// } +// wg.Wait() + +// if testErr != nil { +// t.Fatal(testErr) +// } +// } + +// block, err := engine.ExecutableDataToBlock(*execData) + +// if err != nil { +// t.Fatalf("Failed to convert executable data to block %v", err) +// } + +// if ethservice.BlockChain().CurrentBlock().Number.Uint64() != block.NumberU64()-1 { +// t.Fatalf("Chain head shouldn't be updated") +// } + +// fcState := engine.ForkchoiceStateV1{ +// HeadBlockHash: block.Hash(), +// SafeBlockHash: block.Hash(), +// FinalizedBlockHash: block.Hash(), +// } +// { +// var ( +// wg sync.WaitGroup +// testErr error +// errMu sync.Mutex +// ) + +// wg.Add(10) +// // Do each FCU 10 times +// for ii := 0; ii < 10; ii++ { +// go func() { +// defer wg.Done() + +// if _, err := api.ForkchoiceUpdatedV1(fcState, nil); err != nil { +// errMu.Lock() +// testErr = fmt.Errorf("Failed to insert block: %w", err) +// errMu.Unlock() +// } +// }() +// } +// wg.Wait() + +// if testErr != nil { +// t.Fatal(testErr) +// } +// } + +// if have, want := ethservice.BlockChain().CurrentBlock().Number.Uint64(), block.NumberU64(); have != want { +// t.Fatalf("Chain head should be updated, have %d want %d", have, want) +// } + +// parent = block +// } +// } // TestWithdrawals creates and verifies two post-Shanghai blocks. The first // includes zero withdrawals and the second includes two. -func TestWithdrawals(t *testing.T) { - t.Parallel() - - genesis, blocks := generateMergeChain(10, true) - // Set shanghai time to last block + 5 seconds (first post-merge block) - time := blocks[len(blocks)-1].Time() + 5 - genesis.Config.ShanghaiTime = &time - - n, ethservice := startEthService(t, genesis, blocks) - ethservice.Merger().ReachTTD() - - defer n.Close() - - api := NewConsensusAPI(ethservice) - - // 10: Build Shanghai block with no withdrawals. - parent := ethservice.BlockChain().CurrentHeader() - blockParams := engine.PayloadAttributes{ - Timestamp: parent.Time + 5, - Withdrawals: make([]*types.Withdrawal, 0), - } - fcState := engine.ForkchoiceStateV1{ - HeadBlockHash: parent.Hash(), - } - resp, err := api.ForkchoiceUpdatedV2(fcState, &blockParams) - - if err != nil { - t.Fatalf("error preparing payload, err=%v", err) - } - - if resp.PayloadStatus.Status != engine.VALID { - t.Fatalf("unexpected status (got: %s, want: %s)", resp.PayloadStatus.Status, engine.VALID) - } - - // 10: verify state root is the same as parent - payloadID := (&miner.BuildPayloadArgs{ - Parent: fcState.HeadBlockHash, - Timestamp: blockParams.Timestamp, - FeeRecipient: blockParams.SuggestedFeeRecipient, - Random: blockParams.Random, - Withdrawals: blockParams.Withdrawals, - }).Id() - execData, err := api.GetPayloadV2(payloadID) - - if err != nil { - t.Fatalf("error getting payload, err=%v", err) - } - - if execData.ExecutionPayload.StateRoot != parent.Root { - t.Fatalf("mismatch state roots (got: %s, want: %s)", execData.ExecutionPayload.StateRoot, blocks[8].Root()) - } - - // 10: verify locally built block - if status, err := api.NewPayloadV2(*execData.ExecutionPayload); err != nil { - t.Fatalf("error validating payload: %v", err) - } else if status.Status != engine.VALID { - t.Fatalf("invalid payload") - } - - // 11: build shanghai block with withdrawal - aa := common.Address{0xaa} - bb := common.Address{0xbb} - blockParams = engine.PayloadAttributes{ - Timestamp: execData.ExecutionPayload.Timestamp + 5, - Withdrawals: []*types.Withdrawal{ - { - Index: 0, - Address: aa, - Amount: 32, - }, - { - Index: 1, - Address: bb, - Amount: 33, - }, - }, - } - fcState.HeadBlockHash = execData.ExecutionPayload.BlockHash - _, err = api.ForkchoiceUpdatedV2(fcState, &blockParams) - - if err != nil { - t.Fatalf("error preparing payload, err=%v", err) - } - - // 11: verify locally build block. - payloadID = (&miner.BuildPayloadArgs{ - Parent: fcState.HeadBlockHash, - Timestamp: blockParams.Timestamp, - FeeRecipient: blockParams.SuggestedFeeRecipient, - Random: blockParams.Random, - Withdrawals: blockParams.Withdrawals, - }).Id() - execData, err = api.GetPayloadV2(payloadID) - - if err != nil { - t.Fatalf("error getting payload, err=%v", err) - } - - if status, err := api.NewPayloadV2(*execData.ExecutionPayload); err != nil { - t.Fatalf("error validating payload: %v", err) - } else if status.Status != engine.VALID { - t.Fatalf("invalid payload") - } - - // 11: set block as head. - fcState.HeadBlockHash = execData.ExecutionPayload.BlockHash - _, err = api.ForkchoiceUpdatedV2(fcState, nil) - - if err != nil { - t.Fatalf("error preparing payload, err=%v", err) - } - - // 11: verify withdrawals were processed. - db, _, err := ethservice.APIBackend.StateAndHeaderByNumber(context.Background(), rpc.BlockNumber(execData.ExecutionPayload.Number)) - if err != nil { - t.Fatalf("unable to load db: %v", err) - } - - for i, w := range blockParams.Withdrawals { - // w.Amount is in gwei, balance in wei - if db.GetBalance(w.Address).Uint64() != w.Amount*params.GWei { - t.Fatalf("failed to process withdrawal %d", i) - } - } -} - -func TestNilWithdrawals(t *testing.T) { - t.Parallel() - - genesis, blocks := generateMergeChain(10, true) - // Set shanghai time to last block + 4 seconds (first post-merge block) - time := blocks[len(blocks)-1].Time() + 4 - genesis.Config.ShanghaiTime = &time - - n, ethservice := startEthService(t, genesis, blocks) - ethservice.Merger().ReachTTD() - - defer n.Close() - - api := NewConsensusAPI(ethservice) - parent := ethservice.BlockChain().CurrentHeader() - aa := common.Address{0xaa} - - type test struct { - blockParams engine.PayloadAttributes - wantErr bool - } - - tests := []test{ - // Before Shanghai - { - blockParams: engine.PayloadAttributes{ - Timestamp: parent.Time + 2, - Withdrawals: nil, - }, - wantErr: false, - }, - { - blockParams: engine.PayloadAttributes{ - Timestamp: parent.Time + 2, - Withdrawals: make([]*types.Withdrawal, 0), - }, - wantErr: true, - }, - { - blockParams: engine.PayloadAttributes{ - Timestamp: parent.Time + 2, - Withdrawals: []*types.Withdrawal{ - { - Index: 0, - Address: aa, - Amount: 32, - }, - }, - }, - wantErr: true, - }, - // After Shanghai - { - blockParams: engine.PayloadAttributes{ - Timestamp: parent.Time + 5, - Withdrawals: nil, - }, - wantErr: true, - }, - { - blockParams: engine.PayloadAttributes{ - Timestamp: parent.Time + 5, - Withdrawals: make([]*types.Withdrawal, 0), - }, - wantErr: false, - }, - { - blockParams: engine.PayloadAttributes{ - Timestamp: parent.Time + 5, - Withdrawals: []*types.Withdrawal{ - { - Index: 0, - Address: aa, - Amount: 32, - }, - }, - }, - wantErr: false, - }, - } - - fcState := engine.ForkchoiceStateV1{ - HeadBlockHash: parent.Hash(), - } - - for _, test := range tests { - _, err := api.ForkchoiceUpdatedV2(fcState, &test.blockParams) - if test.wantErr { - if err == nil { - t.Fatal("wanted error on fcuv2 with invalid withdrawals") - } - - continue - } - - if err != nil { - t.Fatalf("error preparing payload, err=%v", err) - } - - // 11: verify locally build block. - payloadID := (&miner.BuildPayloadArgs{ - Parent: fcState.HeadBlockHash, - Timestamp: test.blockParams.Timestamp, - FeeRecipient: test.blockParams.SuggestedFeeRecipient, - Random: test.blockParams.Random, - }).Id() - execData, err := api.GetPayloadV2(payloadID) - - if err != nil { - t.Fatalf("error getting payload, err=%v", err) - } - - if status, err := api.NewPayloadV2(*execData.ExecutionPayload); err != nil { - t.Fatalf("error validating payload: %v", err) - } else if status.Status != engine.VALID { - t.Fatalf("invalid payload") - } - } -} - -func setupBodies(t *testing.T) (*node.Node, *eth.Ethereum, []*types.Block) { - t.Helper() - - genesis, blocks := generateMergeChain(10, true) - // enable shanghai on the last block - time := blocks[len(blocks)-1].Header().Time + 1 - genesis.Config.ShanghaiTime = &time - n, ethservice := startEthService(t, genesis, blocks) - - var ( - parent = ethservice.BlockChain().CurrentBlock() - // This EVM code generates a log when the contract is created. - logCode = common.Hex2Bytes("60606040525b7f24ec1d3ff24c2f6ff210738839dbc339cd45a5294d85c79361016243157aae7b60405180905060405180910390a15b600a8060416000396000f360606040526008565b00") - ) - - callback := func(parent *types.Header) { - statedb, _ := ethservice.BlockChain().StateAt(parent.Root) - nonce := statedb.GetNonce(testAddr) - tx, _ := types.SignTx(types.NewContractCreation(nonce, new(big.Int), 1000000, big.NewInt(2*params.InitialBaseFee), logCode), types.LatestSigner(ethservice.BlockChain().Config()), testKey) - _ = ethservice.TxPool().AddLocal(tx) - } - - withdrawals := make([][]*types.Withdrawal, 10) - withdrawals[0] = nil // should be filtered out by miner - withdrawals[1] = make([]*types.Withdrawal, 0) - - for i := 2; i < len(withdrawals); i++ { - addr := make([]byte, 20) - - _, _ = crand.Read(addr) - - withdrawals[i] = []*types.Withdrawal{ - {Index: rand.Uint64(), Validator: rand.Uint64(), Amount: rand.Uint64(), Address: common.BytesToAddress(addr)}, - } - } - - postShanghaiHeaders := setupBlocks(t, ethservice, 10, parent, callback, withdrawals) - postShanghaiBlocks := make([]*types.Block, len(postShanghaiHeaders)) - - for i, header := range postShanghaiHeaders { - postShanghaiBlocks[i] = ethservice.BlockChain().GetBlock(header.Hash(), header.Number.Uint64()) - } - - return n, ethservice, append(blocks, postShanghaiBlocks...) -} - -func allHashes(blocks []*types.Block) []common.Hash { - hashes := make([]common.Hash, 0, len(blocks)) - - for _, b := range blocks { - hashes = append(hashes, b.Hash()) - } - - return hashes -} -func allBodies(blocks []*types.Block) []*types.Body { - bodies := make([]*types.Body, 0, len(blocks)) - - for _, b := range blocks { - bodies = append(bodies, b.Body()) - } - - return bodies -} - -func TestGetBlockBodiesByHash(t *testing.T) { - t.Parallel() - - node, eth, blocks := setupBodies(t) - api := NewConsensusAPI(eth) - - defer node.Close() - - tests := []struct { - results []*types.Body - hashes []common.Hash - }{ - // First pow block - { - results: []*types.Body{eth.BlockChain().GetBlockByNumber(0).Body()}, - hashes: []common.Hash{eth.BlockChain().GetBlockByNumber(0).Hash()}, - }, - // Last pow block - { - results: []*types.Body{blocks[9].Body()}, - hashes: []common.Hash{blocks[9].Hash()}, - }, - // First post-merge block - { - results: []*types.Body{blocks[10].Body()}, - hashes: []common.Hash{blocks[10].Hash()}, - }, - // Pre & post merge blocks - { - results: []*types.Body{blocks[0].Body(), blocks[9].Body(), blocks[14].Body()}, - hashes: []common.Hash{blocks[0].Hash(), blocks[9].Hash(), blocks[14].Hash()}, - }, - // unavailable block - { - results: []*types.Body{blocks[0].Body(), nil, blocks[14].Body()}, - hashes: []common.Hash{blocks[0].Hash(), {1, 2}, blocks[14].Hash()}, - }, - // same block multiple times - { - results: []*types.Body{blocks[0].Body(), nil, blocks[0].Body(), blocks[0].Body()}, - hashes: []common.Hash{blocks[0].Hash(), {1, 2}, blocks[0].Hash(), blocks[0].Hash()}, - }, - // all blocks - { - results: allBodies(blocks), - hashes: allHashes(blocks), - }, - } - - for k, test := range tests { - result := api.GetPayloadBodiesByHashV1(test.hashes) - for i, r := range result { - if !equalBody(test.results[i], r) { - t.Fatalf("test %v: invalid response: expected %+v got %+v", k, test.results[i], r) - } - } - } -} - -func TestGetBlockBodiesByRange(t *testing.T) { - t.Parallel() - - node, eth, blocks := setupBodies(t) - api := NewConsensusAPI(eth) - - defer node.Close() - - tests := []struct { - results []*types.Body - start hexutil.Uint64 - count hexutil.Uint64 - }{ - { - results: []*types.Body{blocks[9].Body()}, - start: 10, - count: 1, - }, - // Genesis - { - results: []*types.Body{blocks[0].Body()}, - start: 1, - count: 1, - }, - // First post-merge block - { - results: []*types.Body{blocks[9].Body()}, - start: 10, - count: 1, - }, - // Pre & post merge blocks - { - results: []*types.Body{blocks[7].Body(), blocks[8].Body(), blocks[9].Body(), blocks[10].Body()}, - start: 8, - count: 4, - }, - // unavailable block - { - results: []*types.Body{blocks[18].Body(), blocks[19].Body()}, - start: 19, - count: 3, - }, - // unavailable block - { - results: []*types.Body{blocks[19].Body()}, - start: 20, - count: 2, - }, - { - results: []*types.Body{blocks[19].Body()}, - start: 20, - count: 1, - }, - // whole range unavailable - { - results: make([]*types.Body, 0), - start: 22, - count: 2, - }, - // allBlocks - { - results: allBodies(blocks), - start: 1, - count: hexutil.Uint64(len(blocks)), - }, - } - - for k, test := range tests { - result, err := api.GetPayloadBodiesByRangeV1(test.start, test.count) - if err != nil { - t.Fatal(err) - } - - if len(result) == len(test.results) { - for i, r := range result { - if !equalBody(test.results[i], r) { - t.Fatalf("test %d: invalid response: expected \n%+v\ngot\n%+v", k, test.results[i], r) - } - } - } else { - t.Fatalf("test %d: invalid length want %v got %v", k, len(test.results), len(result)) - } - } -} - -func TestGetBlockBodiesByRangeInvalidParams(t *testing.T) { - t.Parallel() - - node, eth, _ := setupBodies(t) - api := NewConsensusAPI(eth) - - defer node.Close() - - tests := []struct { - start hexutil.Uint64 - count hexutil.Uint64 - want *engine.EngineAPIError - }{ - // Genesis - { - start: 0, - count: 1, - want: engine.InvalidParams, - }, - // No block requested - { - start: 1, - count: 0, - want: engine.InvalidParams, - }, - // Genesis & no block - { - start: 0, - count: 0, - want: engine.InvalidParams, - }, - // More than 1024 blocks - { - start: 1, - count: 1025, - want: engine.TooLargeRequest, - }, - } - - for i, tc := range tests { - result, err := api.GetPayloadBodiesByRangeV1(tc.start, tc.count) - if err == nil { - t.Fatalf("test %d: expected error, got %v", i, result) - } - - if have, want := err.Error(), tc.want.Error(); have != want { - t.Fatalf("test %d: have %s, want %s", i, have, want) - } - } -} - -func equalBody(a *types.Body, b *engine.ExecutionPayloadBodyV1) bool { - if a == nil && b == nil { - return true - } else if a == nil || b == nil { - return false - } - - if len(a.Transactions) != len(b.TransactionData) { - return false - } - - for i, tx := range a.Transactions { - data, _ := tx.MarshalBinary() - if !bytes.Equal(data, b.TransactionData[i]) { - return false - } - } - - return reflect.DeepEqual(a.Withdrawals, b.Withdrawals) -} +// func TestWithdrawals(t *testing.T) { +// t.Parallel() + +// genesis, blocks := generateMergeChain(10, true) +// // Set shanghai time to last block + 5 seconds (first post-merge block) +// number := new(big.Int).Add(blocks[len(blocks)-1].Header().Number, big.NewInt(5)) +// genesis.Config.ShanghaiBlock = number + +// n, ethservice := startEthService(t, genesis, blocks) +// ethservice.Merger().ReachTTD() + +// defer n.Close() + +// api := NewConsensusAPI(ethservice) + +// // 10: Build Shanghai block with no withdrawals. +// parent := ethservice.BlockChain().CurrentHeader() +// blockParams := engine.PayloadAttributes{ +// Timestamp: parent.Time + 5, +// Withdrawals: make([]*types.Withdrawal, 0), +// } +// fcState := engine.ForkchoiceStateV1{ +// HeadBlockHash: parent.Hash(), +// } +// resp, err := api.ForkchoiceUpdatedV2(fcState, &blockParams) + +// if err != nil { +// t.Fatalf("error preparing payload, err=%v", err) +// } + +// if resp.PayloadStatus.Status != engine.VALID { +// t.Fatalf("unexpected status (got: %s, want: %s)", resp.PayloadStatus.Status, engine.VALID) +// } + +// // 10: verify state root is the same as parent +// payloadID := (&miner.BuildPayloadArgs{ +// Parent: fcState.HeadBlockHash, +// Timestamp: blockParams.Timestamp, +// FeeRecipient: blockParams.SuggestedFeeRecipient, +// Random: blockParams.Random, +// Withdrawals: blockParams.Withdrawals, +// }).Id() +// execData, err := api.GetPayloadV2(payloadID) + +// if err != nil { +// t.Fatalf("error getting payload, err=%v", err) +// } + +// if execData.ExecutionPayload.StateRoot != parent.Root { +// t.Fatalf("mismatch state roots (got: %s, want: %s)", execData.ExecutionPayload.StateRoot, blocks[8].Root()) +// } + +// // 10: verify locally built block +// if status, err := api.NewPayloadV2(*execData.ExecutionPayload); err != nil { +// t.Fatalf("error validating payload: %v", err) +// } else if status.Status != engine.VALID { +// t.Fatalf("invalid payload") +// } + +// // 11: build shanghai block with withdrawal +// aa := common.Address{0xaa} +// bb := common.Address{0xbb} +// blockParams = engine.PayloadAttributes{ +// Timestamp: execData.ExecutionPayload.Timestamp + 5, +// Withdrawals: []*types.Withdrawal{ +// { +// Index: 0, +// Address: aa, +// Amount: 32, +// }, +// { +// Index: 1, +// Address: bb, +// Amount: 33, +// }, +// }, +// } +// fcState.HeadBlockHash = execData.ExecutionPayload.BlockHash +// _, err = api.ForkchoiceUpdatedV2(fcState, &blockParams) + +// if err != nil { +// t.Fatalf("error preparing payload, err=%v", err) +// } + +// // 11: verify locally build block. +// payloadID = (&miner.BuildPayloadArgs{ +// Parent: fcState.HeadBlockHash, +// Timestamp: blockParams.Timestamp, +// FeeRecipient: blockParams.SuggestedFeeRecipient, +// Random: blockParams.Random, +// Withdrawals: blockParams.Withdrawals, +// }).Id() +// execData, err = api.GetPayloadV2(payloadID) + +// if err != nil { +// t.Fatalf("error getting payload, err=%v", err) +// } + +// if status, err := api.NewPayloadV2(*execData.ExecutionPayload); err != nil { +// t.Fatalf("error validating payload: %v", err) +// } else if status.Status != engine.VALID { +// t.Fatalf("invalid payload") +// } + +// // 11: set block as head. +// fcState.HeadBlockHash = execData.ExecutionPayload.BlockHash +// _, err = api.ForkchoiceUpdatedV2(fcState, nil) + +// if err != nil { +// t.Fatalf("error preparing payload, err=%v", err) +// } + +// // 11: verify withdrawals were processed. +// db, _, err := ethservice.APIBackend.StateAndHeaderByNumber(context.Background(), rpc.BlockNumber(execData.ExecutionPayload.Number)) +// if err != nil { +// t.Fatalf("unable to load db: %v", err) +// } + +// for i, w := range blockParams.Withdrawals { +// // w.Amount is in gwei, balance in wei +// if db.GetBalance(w.Address).Uint64() != w.Amount*params.GWei { +// t.Fatalf("failed to process withdrawal %d", i) +// } +// } +// } + +// func TestNilWithdrawals(t *testing.T) { +// t.Parallel() + +// genesis, blocks := generateMergeChain(10, true) +// // Set shanghai time to last block + 4 seconds (first post-merge block) +// block := new(big.Int).Add(blocks[len(blocks)-1].Header().Number, big.NewInt(4)) +// genesis.Config.ShanghaiBlock = block + +// n, ethservice := startEthService(t, genesis, blocks) +// ethservice.Merger().ReachTTD() + +// defer n.Close() + +// api := NewConsensusAPI(ethservice) +// parent := ethservice.BlockChain().CurrentHeader() +// aa := common.Address{0xaa} + +// type test struct { +// blockParams engine.PayloadAttributes +// wantErr bool +// } + +// tests := []test{ +// // Before Shanghai +// { +// blockParams: engine.PayloadAttributes{ +// Timestamp: parent.Time + 2, +// Withdrawals: nil, +// }, +// wantErr: false, +// }, +// { +// blockParams: engine.PayloadAttributes{ +// Timestamp: parent.Time + 2, +// Withdrawals: make([]*types.Withdrawal, 0), +// }, +// wantErr: true, +// }, +// { +// blockParams: engine.PayloadAttributes{ +// Timestamp: parent.Time + 2, +// Withdrawals: []*types.Withdrawal{ +// { +// Index: 0, +// Address: aa, +// Amount: 32, +// }, +// }, +// }, +// wantErr: true, +// }, +// // After Shanghai +// { +// blockParams: engine.PayloadAttributes{ +// Timestamp: parent.Time + 5, +// Withdrawals: nil, +// }, +// wantErr: true, +// }, +// { +// blockParams: engine.PayloadAttributes{ +// Timestamp: parent.Time + 5, +// Withdrawals: make([]*types.Withdrawal, 0), +// }, +// wantErr: false, +// }, +// { +// blockParams: engine.PayloadAttributes{ +// Timestamp: parent.Time + 5, +// Withdrawals: []*types.Withdrawal{ +// { +// Index: 0, +// Address: aa, +// Amount: 32, +// }, +// }, +// }, +// wantErr: false, +// }, +// } + +// fcState := engine.ForkchoiceStateV1{ +// HeadBlockHash: parent.Hash(), +// } + +// for _, test := range tests { +// _, err := api.ForkchoiceUpdatedV2(fcState, &test.blockParams) +// if test.wantErr { +// if err == nil { +// t.Fatal("wanted error on fcuv2 with invalid withdrawals") +// } + +// continue +// } + +// if err != nil { +// t.Fatalf("error preparing payload, err=%v", err) +// } + +// // 11: verify locally build block. +// payloadID := (&miner.BuildPayloadArgs{ +// Parent: fcState.HeadBlockHash, +// Timestamp: test.blockParams.Timestamp, +// FeeRecipient: test.blockParams.SuggestedFeeRecipient, +// Random: test.blockParams.Random, +// }).Id() +// execData, err := api.GetPayloadV2(payloadID) + +// if err != nil { +// t.Fatalf("error getting payload, err=%v", err) +// } + +// if status, err := api.NewPayloadV2(*execData.ExecutionPayload); err != nil { +// t.Fatalf("error validating payload: %v", err) +// } else if status.Status != engine.VALID { +// t.Fatalf("invalid payload") +// } +// } +// } + +// func setupBodies(t *testing.T) (*node.Node, *eth.Ethereum, []*types.Block) { +// t.Helper() + +// genesis, blocks := generateMergeChain(10, true) +// // enable shanghai on the last block +// number := new(big.Int).Add(blocks[len(blocks)-1].Header().Number, big.NewInt(1)) +// genesis.Config.ShanghaiBlock = number +// n, ethservice := startEthService(t, genesis, blocks) + +// var ( +// parent = ethservice.BlockChain().CurrentBlock() +// // This EVM code generates a log when the contract is created. +// logCode = common.Hex2Bytes("60606040525b7f24ec1d3ff24c2f6ff210738839dbc339cd45a5294d85c79361016243157aae7b60405180905060405180910390a15b600a8060416000396000f360606040526008565b00") +// ) + +// callback := func(parent *types.Header) { +// statedb, _ := ethservice.BlockChain().StateAt(parent.Root) +// nonce := statedb.GetNonce(testAddr) +// tx, _ := types.SignTx(types.NewContractCreation(nonce, new(big.Int), 1000000, big.NewInt(2*params.InitialBaseFee), logCode), types.LatestSigner(ethservice.BlockChain().Config()), testKey) +// _ = ethservice.TxPool().AddLocal(tx) +// } + +// withdrawals := make([][]*types.Withdrawal, 10) +// withdrawals[0] = nil // should be filtered out by miner +// withdrawals[1] = make([]*types.Withdrawal, 0) + +// for i := 2; i < len(withdrawals); i++ { +// addr := make([]byte, 20) + +// _, _ = crand.Read(addr) + +// withdrawals[i] = []*types.Withdrawal{ +// {Index: rand.Uint64(), Validator: rand.Uint64(), Amount: rand.Uint64(), Address: common.BytesToAddress(addr)}, +// } +// } + +// postShanghaiHeaders := setupBlocks(t, ethservice, 10, parent, callback, withdrawals) +// postShanghaiBlocks := make([]*types.Block, len(postShanghaiHeaders)) + +// for i, header := range postShanghaiHeaders { +// postShanghaiBlocks[i] = ethservice.BlockChain().GetBlock(header.Hash(), header.Number.Uint64()) +// } + +// return n, ethservice, append(blocks, postShanghaiBlocks...) +// } + +// func allHashes(blocks []*types.Block) []common.Hash { +// hashes := make([]common.Hash, 0, len(blocks)) + +// for _, b := range blocks { +// hashes = append(hashes, b.Hash()) +// } + +// return hashes +// } +// func allBodies(blocks []*types.Block) []*types.Body { +// bodies := make([]*types.Body, 0, len(blocks)) + +// for _, b := range blocks { +// bodies = append(bodies, b.Body()) +// } + +// return bodies +// } + +// func TestGetBlockBodiesByHash(t *testing.T) { +// t.Parallel() + +// node, eth, blocks := setupBodies(t) +// api := NewConsensusAPI(eth) + +// defer node.Close() + +// tests := []struct { +// results []*types.Body +// hashes []common.Hash +// }{ +// // First pow block +// { +// results: []*types.Body{eth.BlockChain().GetBlockByNumber(0).Body()}, +// hashes: []common.Hash{eth.BlockChain().GetBlockByNumber(0).Hash()}, +// }, +// // Last pow block +// { +// results: []*types.Body{blocks[9].Body()}, +// hashes: []common.Hash{blocks[9].Hash()}, +// }, +// // First post-merge block +// { +// results: []*types.Body{blocks[10].Body()}, +// hashes: []common.Hash{blocks[10].Hash()}, +// }, +// // Pre & post merge blocks +// { +// results: []*types.Body{blocks[0].Body(), blocks[9].Body(), blocks[14].Body()}, +// hashes: []common.Hash{blocks[0].Hash(), blocks[9].Hash(), blocks[14].Hash()}, +// }, +// // unavailable block +// { +// results: []*types.Body{blocks[0].Body(), nil, blocks[14].Body()}, +// hashes: []common.Hash{blocks[0].Hash(), {1, 2}, blocks[14].Hash()}, +// }, +// // same block multiple times +// { +// results: []*types.Body{blocks[0].Body(), nil, blocks[0].Body(), blocks[0].Body()}, +// hashes: []common.Hash{blocks[0].Hash(), {1, 2}, blocks[0].Hash(), blocks[0].Hash()}, +// }, +// // all blocks +// { +// results: allBodies(blocks), +// hashes: allHashes(blocks), +// }, +// } + +// for k, test := range tests { +// result := api.GetPayloadBodiesByHashV1(test.hashes) +// for i, r := range result { +// if !equalBody(test.results[i], r) { +// t.Fatalf("test %v: invalid response: expected %+v got %+v", k, test.results[i], r) +// } +// } +// } +// } + +// func TestGetBlockBodiesByRange(t *testing.T) { +// t.Parallel() + +// node, eth, blocks := setupBodies(t) +// api := NewConsensusAPI(eth) + +// defer node.Close() + +// tests := []struct { +// results []*types.Body +// start hexutil.Uint64 +// count hexutil.Uint64 +// }{ +// { +// results: []*types.Body{blocks[9].Body()}, +// start: 10, +// count: 1, +// }, +// // Genesis +// { +// results: []*types.Body{blocks[0].Body()}, +// start: 1, +// count: 1, +// }, +// // First post-merge block +// { +// results: []*types.Body{blocks[9].Body()}, +// start: 10, +// count: 1, +// }, +// // Pre & post merge blocks +// { +// results: []*types.Body{blocks[7].Body(), blocks[8].Body(), blocks[9].Body(), blocks[10].Body()}, +// start: 8, +// count: 4, +// }, +// // unavailable block +// { +// results: []*types.Body{blocks[18].Body(), blocks[19].Body()}, +// start: 19, +// count: 3, +// }, +// // unavailable block +// { +// results: []*types.Body{blocks[19].Body()}, +// start: 20, +// count: 2, +// }, +// { +// results: []*types.Body{blocks[19].Body()}, +// start: 20, +// count: 1, +// }, +// // whole range unavailable +// { +// results: make([]*types.Body, 0), +// start: 22, +// count: 2, +// }, +// // allBlocks +// { +// results: allBodies(blocks), +// start: 1, +// count: hexutil.Uint64(len(blocks)), +// }, +// } + +// for k, test := range tests { +// result, err := api.GetPayloadBodiesByRangeV1(test.start, test.count) +// if err != nil { +// t.Fatal(err) +// } + +// if len(result) == len(test.results) { +// for i, r := range result { +// if !equalBody(test.results[i], r) { +// t.Fatalf("test %d: invalid response: expected \n%+v\ngot\n%+v", k, test.results[i], r) +// } +// } +// } else { +// t.Fatalf("test %d: invalid length want %v got %v", k, len(test.results), len(result)) +// } +// } +// } + +// func TestGetBlockBodiesByRangeInvalidParams(t *testing.T) { +// t.Parallel() + +// node, eth, _ := setupBodies(t) +// api := NewConsensusAPI(eth) + +// defer node.Close() + +// tests := []struct { +// start hexutil.Uint64 +// count hexutil.Uint64 +// want *engine.EngineAPIError +// }{ +// // Genesis +// { +// start: 0, +// count: 1, +// want: engine.InvalidParams, +// }, +// // No block requested +// { +// start: 1, +// count: 0, +// want: engine.InvalidParams, +// }, +// // Genesis & no block +// { +// start: 0, +// count: 0, +// want: engine.InvalidParams, +// }, +// // More than 1024 blocks +// { +// start: 1, +// count: 1025, +// want: engine.TooLargeRequest, +// }, +// } + +// for i, tc := range tests { +// result, err := api.GetPayloadBodiesByRangeV1(tc.start, tc.count) +// if err == nil { +// t.Fatalf("test %d: expected error, got %v", i, result) +// } + +// if have, want := err.Error(), tc.want.Error(); have != want { +// t.Fatalf("test %d: have %s, want %s", i, have, want) +// } +// } +// } + +// func equalBody(a *types.Body, b *engine.ExecutionPayloadBodyV1) bool { +// if a == nil && b == nil { +// return true +// } else if a == nil || b == nil { +// return false +// } + +// if len(a.Transactions) != len(b.TransactionData) { +// return false +// } + +// for i, tx := range a.Transactions { +// data, _ := tx.MarshalBinary() +// if !bytes.Equal(data, b.TransactionData[i]) { +// return false +// } +// } + +// return reflect.DeepEqual(a.Withdrawals, b.Withdrawals) +// } diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 7a037aec31..0d1528bb1e 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -18,6 +18,7 @@ package ethconfig import ( + "math/big" "os" "os/user" "path/filepath" @@ -224,9 +225,8 @@ type Config struct { // CheckpointOracle is the configuration for checkpoint oracle. CheckpointOracle *params.CheckpointOracleConfig `toml:",omitempty"` - // TODO marcello double check // OverrideShanghai (TODO: remove after the fork) - OverrideShanghai *uint64 `toml:",omitempty"` + OverrideShanghai *big.Int `toml:",omitempty"` // URL to connect to Heimdall node HeimdallURL string diff --git a/eth/ethconfig/gen_config.go b/eth/ethconfig/gen_config.go index 4ef94b47fe..94b2c2f194 100644 --- a/eth/ethconfig/gen_config.go +++ b/eth/ethconfig/gen_config.go @@ -3,6 +3,7 @@ package ethconfig import ( + "math/big" "time" "github.com/ethereum/go-ethereum/common" @@ -18,51 +19,65 @@ import ( // MarshalTOML marshals as TOML. func (c Config) MarshalTOML() (interface{}, error) { type Config struct { - Genesis *core.Genesis `toml:",omitempty"` - NetworkId uint64 - SyncMode downloader.SyncMode - EthDiscoveryURLs []string - SnapDiscoveryURLs []string - NoPruning bool - NoPrefetch bool - TxLookupLimit uint64 `toml:",omitempty"` - RequiredBlocks map[uint64]common.Hash `toml:"-"` - LightServ int `toml:",omitempty"` - LightIngress int `toml:",omitempty"` - LightEgress int `toml:",omitempty"` - LightPeers int `toml:",omitempty"` - LightNoPrune bool `toml:",omitempty"` - LightNoSyncServe bool `toml:",omitempty"` - SyncFromCheckpoint bool `toml:",omitempty"` - UltraLightServers []string `toml:",omitempty"` - UltraLightFraction int `toml:",omitempty"` - UltraLightOnlyAnnounce bool `toml:",omitempty"` - SkipBcVersionCheck bool `toml:"-"` - DatabaseHandles int `toml:"-"` - DatabaseCache int - DatabaseFreezer string - TrieCleanCache int - TrieCleanCacheJournal string `toml:",omitempty"` - TrieCleanCacheRejournal time.Duration `toml:",omitempty"` - TrieDirtyCache int - TrieTimeout time.Duration - SnapshotCache int - Preimages bool - FilterLogCacheSize int - Miner miner.Config - Ethash ethash.Config - TxPool txpool.Config - GPO gasprice.Config - EnablePreimageRecording bool - DocRoot string `toml:"-"` - RPCGasCap uint64 - RPCEVMTimeout time.Duration - RPCTxFeeCap float64 - Checkpoint *params.TrustedCheckpoint `toml:",omitempty"` - CheckpointOracle *params.CheckpointOracleConfig `toml:",omitempty"` - OverrideShanghai *uint64 `toml:",omitempty"` + Genesis *core.Genesis `toml:",omitempty"` + NetworkId uint64 + SyncMode downloader.SyncMode + EthDiscoveryURLs []string + SnapDiscoveryURLs []string + NoPruning bool + NoPrefetch bool + TxLookupLimit uint64 `toml:",omitempty"` + RequiredBlocks map[uint64]common.Hash `toml:"-"` + LightServ int `toml:",omitempty"` + LightIngress int `toml:",omitempty"` + LightEgress int `toml:",omitempty"` + LightPeers int `toml:",omitempty"` + LightNoPrune bool `toml:",omitempty"` + LightNoSyncServe bool `toml:",omitempty"` + SyncFromCheckpoint bool `toml:",omitempty"` + UltraLightServers []string `toml:",omitempty"` + UltraLightFraction int `toml:",omitempty"` + UltraLightOnlyAnnounce bool `toml:",omitempty"` + SkipBcVersionCheck bool `toml:"-"` + DatabaseHandles int `toml:"-"` + DatabaseCache int + DatabaseFreezer string + LevelDbCompactionTableSize uint64 + LevelDbCompactionTableSizeMultiplier float64 + LevelDbCompactionTotalSize uint64 + LevelDbCompactionTotalSizeMultiplier float64 + TrieCleanCache int + TrieCleanCacheJournal string `toml:",omitempty"` + TrieCleanCacheRejournal time.Duration `toml:",omitempty"` + TrieDirtyCache int + TrieTimeout time.Duration + SnapshotCache int + Preimages bool + TriesInMemory uint64 + FilterLogCacheSize int + Miner miner.Config + Ethash ethash.Config + TxPool txpool.Config + GPO gasprice.Config + EnablePreimageRecording bool + DocRoot string `toml:"-"` + RPCGasCap uint64 + RPCReturnDataLimit uint64 + RPCEVMTimeout time.Duration + RPCTxFeeCap float64 + Checkpoint *params.TrustedCheckpoint `toml:",omitempty"` + CheckpointOracle *params.CheckpointOracleConfig `toml:",omitempty"` + OverrideShanghai *big.Int `toml:",omitempty"` + HeimdallURL string + WithoutHeimdall bool + HeimdallgRPCAddress string + RunHeimdall bool + RunHeimdallArgs string + UseHeimdallApp bool + BorLogs bool + ParallelEVM core.ParallelEVMConfig `toml:",omitempty"` + DevFakeAuthor bool `hcl:"devfakeauthor,optional" toml:"devfakeauthor,optional"` } - var enc Config enc.Genesis = c.Genesis enc.NetworkId = c.NetworkId @@ -87,6 +102,10 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.DatabaseHandles = c.DatabaseHandles enc.DatabaseCache = c.DatabaseCache enc.DatabaseFreezer = c.DatabaseFreezer + enc.LevelDbCompactionTableSize = c.LevelDbCompactionTableSize + enc.LevelDbCompactionTableSizeMultiplier = c.LevelDbCompactionTableSizeMultiplier + enc.LevelDbCompactionTotalSize = c.LevelDbCompactionTotalSize + enc.LevelDbCompactionTotalSizeMultiplier = c.LevelDbCompactionTotalSizeMultiplier enc.TrieCleanCache = c.TrieCleanCache enc.TrieCleanCacheJournal = c.TrieCleanCacheJournal enc.TrieCleanCacheRejournal = c.TrieCleanCacheRejournal @@ -94,6 +113,7 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.TrieTimeout = c.TrieTimeout enc.SnapshotCache = c.SnapshotCache enc.Preimages = c.Preimages + enc.TriesInMemory = c.TriesInMemory enc.FilterLogCacheSize = c.FilterLogCacheSize enc.Miner = c.Miner enc.Ethash = c.Ethash @@ -102,239 +122,263 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.EnablePreimageRecording = c.EnablePreimageRecording enc.DocRoot = c.DocRoot enc.RPCGasCap = c.RPCGasCap + enc.RPCReturnDataLimit = c.RPCReturnDataLimit enc.RPCEVMTimeout = c.RPCEVMTimeout enc.RPCTxFeeCap = c.RPCTxFeeCap enc.Checkpoint = c.Checkpoint enc.CheckpointOracle = c.CheckpointOracle enc.OverrideShanghai = c.OverrideShanghai - + enc.HeimdallURL = c.HeimdallURL + enc.WithoutHeimdall = c.WithoutHeimdall + enc.HeimdallgRPCAddress = c.HeimdallgRPCAddress + enc.RunHeimdall = c.RunHeimdall + enc.RunHeimdallArgs = c.RunHeimdallArgs + enc.UseHeimdallApp = c.UseHeimdallApp + enc.BorLogs = c.BorLogs + enc.ParallelEVM = c.ParallelEVM + enc.DevFakeAuthor = c.DevFakeAuthor return &enc, nil } // UnmarshalTOML unmarshals from TOML. func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { type Config struct { - Genesis *core.Genesis `toml:",omitempty"` - NetworkId *uint64 - SyncMode *downloader.SyncMode - EthDiscoveryURLs []string - SnapDiscoveryURLs []string - NoPruning *bool - NoPrefetch *bool - TxLookupLimit *uint64 `toml:",omitempty"` - RequiredBlocks map[uint64]common.Hash `toml:"-"` - LightServ *int `toml:",omitempty"` - LightIngress *int `toml:",omitempty"` - LightEgress *int `toml:",omitempty"` - LightPeers *int `toml:",omitempty"` - LightNoPrune *bool `toml:",omitempty"` - LightNoSyncServe *bool `toml:",omitempty"` - SyncFromCheckpoint *bool `toml:",omitempty"` - UltraLightServers []string `toml:",omitempty"` - UltraLightFraction *int `toml:",omitempty"` - UltraLightOnlyAnnounce *bool `toml:",omitempty"` - SkipBcVersionCheck *bool `toml:"-"` - DatabaseHandles *int `toml:"-"` - DatabaseCache *int - DatabaseFreezer *string - TrieCleanCache *int - TrieCleanCacheJournal *string `toml:",omitempty"` - TrieCleanCacheRejournal *time.Duration `toml:",omitempty"` - TrieDirtyCache *int - TrieTimeout *time.Duration - SnapshotCache *int - Preimages *bool - FilterLogCacheSize *int - Miner *miner.Config - Ethash *ethash.Config - TxPool *txpool.Config - GPO *gasprice.Config - EnablePreimageRecording *bool - DocRoot *string `toml:"-"` - RPCGasCap *uint64 - RPCEVMTimeout *time.Duration - RPCTxFeeCap *float64 - Checkpoint *params.TrustedCheckpoint `toml:",omitempty"` - CheckpointOracle *params.CheckpointOracleConfig `toml:",omitempty"` - OverrideShanghai *uint64 `toml:",omitempty"` + Genesis *core.Genesis `toml:",omitempty"` + NetworkId *uint64 + SyncMode *downloader.SyncMode + EthDiscoveryURLs []string + SnapDiscoveryURLs []string + NoPruning *bool + NoPrefetch *bool + TxLookupLimit *uint64 `toml:",omitempty"` + RequiredBlocks map[uint64]common.Hash `toml:"-"` + LightServ *int `toml:",omitempty"` + LightIngress *int `toml:",omitempty"` + LightEgress *int `toml:",omitempty"` + LightPeers *int `toml:",omitempty"` + LightNoPrune *bool `toml:",omitempty"` + LightNoSyncServe *bool `toml:",omitempty"` + SyncFromCheckpoint *bool `toml:",omitempty"` + UltraLightServers []string `toml:",omitempty"` + UltraLightFraction *int `toml:",omitempty"` + UltraLightOnlyAnnounce *bool `toml:",omitempty"` + SkipBcVersionCheck *bool `toml:"-"` + DatabaseHandles *int `toml:"-"` + DatabaseCache *int + DatabaseFreezer *string + LevelDbCompactionTableSize *uint64 + LevelDbCompactionTableSizeMultiplier *float64 + LevelDbCompactionTotalSize *uint64 + LevelDbCompactionTotalSizeMultiplier *float64 + TrieCleanCache *int + TrieCleanCacheJournal *string `toml:",omitempty"` + TrieCleanCacheRejournal *time.Duration `toml:",omitempty"` + TrieDirtyCache *int + TrieTimeout *time.Duration + SnapshotCache *int + Preimages *bool + TriesInMemory *uint64 + FilterLogCacheSize *int + Miner *miner.Config + Ethash *ethash.Config + TxPool *txpool.Config + GPO *gasprice.Config + EnablePreimageRecording *bool + DocRoot *string `toml:"-"` + RPCGasCap *uint64 + RPCReturnDataLimit *uint64 + RPCEVMTimeout *time.Duration + RPCTxFeeCap *float64 + Checkpoint *params.TrustedCheckpoint `toml:",omitempty"` + CheckpointOracle *params.CheckpointOracleConfig `toml:",omitempty"` + OverrideShanghai *big.Int `toml:",omitempty"` + HeimdallURL *string + WithoutHeimdall *bool + HeimdallgRPCAddress *string + RunHeimdall *bool + RunHeimdallArgs *string + UseHeimdallApp *bool + BorLogs *bool + ParallelEVM *core.ParallelEVMConfig `toml:",omitempty"` + DevFakeAuthor *bool `hcl:"devfakeauthor,optional" toml:"devfakeauthor,optional"` } - var dec Config if err := unmarshal(&dec); err != nil { return err } - if dec.Genesis != nil { c.Genesis = dec.Genesis } - if dec.NetworkId != nil { c.NetworkId = *dec.NetworkId } - if dec.SyncMode != nil { c.SyncMode = *dec.SyncMode } - if dec.EthDiscoveryURLs != nil { c.EthDiscoveryURLs = dec.EthDiscoveryURLs } - if dec.SnapDiscoveryURLs != nil { c.SnapDiscoveryURLs = dec.SnapDiscoveryURLs } - if dec.NoPruning != nil { c.NoPruning = *dec.NoPruning } - if dec.NoPrefetch != nil { c.NoPrefetch = *dec.NoPrefetch } - if dec.TxLookupLimit != nil { c.TxLookupLimit = *dec.TxLookupLimit } - if dec.RequiredBlocks != nil { c.RequiredBlocks = dec.RequiredBlocks } - if dec.LightServ != nil { c.LightServ = *dec.LightServ } - if dec.LightIngress != nil { c.LightIngress = *dec.LightIngress } - if dec.LightEgress != nil { c.LightEgress = *dec.LightEgress } - if dec.LightPeers != nil { c.LightPeers = *dec.LightPeers } - if dec.LightNoPrune != nil { c.LightNoPrune = *dec.LightNoPrune } - if dec.LightNoSyncServe != nil { c.LightNoSyncServe = *dec.LightNoSyncServe } - if dec.SyncFromCheckpoint != nil { c.SyncFromCheckpoint = *dec.SyncFromCheckpoint } - if dec.UltraLightServers != nil { c.UltraLightServers = dec.UltraLightServers } - if dec.UltraLightFraction != nil { c.UltraLightFraction = *dec.UltraLightFraction } - if dec.UltraLightOnlyAnnounce != nil { c.UltraLightOnlyAnnounce = *dec.UltraLightOnlyAnnounce } - if dec.SkipBcVersionCheck != nil { c.SkipBcVersionCheck = *dec.SkipBcVersionCheck } - if dec.DatabaseHandles != nil { c.DatabaseHandles = *dec.DatabaseHandles } - if dec.DatabaseCache != nil { c.DatabaseCache = *dec.DatabaseCache } - if dec.DatabaseFreezer != nil { c.DatabaseFreezer = *dec.DatabaseFreezer } - + if dec.LevelDbCompactionTableSize != nil { + c.LevelDbCompactionTableSize = *dec.LevelDbCompactionTableSize + } + if dec.LevelDbCompactionTableSizeMultiplier != nil { + c.LevelDbCompactionTableSizeMultiplier = *dec.LevelDbCompactionTableSizeMultiplier + } + if dec.LevelDbCompactionTotalSize != nil { + c.LevelDbCompactionTotalSize = *dec.LevelDbCompactionTotalSize + } + if dec.LevelDbCompactionTotalSizeMultiplier != nil { + c.LevelDbCompactionTotalSizeMultiplier = *dec.LevelDbCompactionTotalSizeMultiplier + } if dec.TrieCleanCache != nil { c.TrieCleanCache = *dec.TrieCleanCache } - if dec.TrieCleanCacheJournal != nil { c.TrieCleanCacheJournal = *dec.TrieCleanCacheJournal } - if dec.TrieCleanCacheRejournal != nil { c.TrieCleanCacheRejournal = *dec.TrieCleanCacheRejournal } - if dec.TrieDirtyCache != nil { c.TrieDirtyCache = *dec.TrieDirtyCache } - if dec.TrieTimeout != nil { c.TrieTimeout = *dec.TrieTimeout } - if dec.SnapshotCache != nil { c.SnapshotCache = *dec.SnapshotCache } - if dec.Preimages != nil { c.Preimages = *dec.Preimages } - + if dec.TriesInMemory != nil { + c.TriesInMemory = *dec.TriesInMemory + } if dec.FilterLogCacheSize != nil { c.FilterLogCacheSize = *dec.FilterLogCacheSize } - if dec.Miner != nil { c.Miner = *dec.Miner } - if dec.Ethash != nil { c.Ethash = *dec.Ethash } - if dec.TxPool != nil { c.TxPool = *dec.TxPool } - if dec.GPO != nil { c.GPO = *dec.GPO } - if dec.EnablePreimageRecording != nil { c.EnablePreimageRecording = *dec.EnablePreimageRecording } - if dec.DocRoot != nil { c.DocRoot = *dec.DocRoot } - if dec.RPCGasCap != nil { c.RPCGasCap = *dec.RPCGasCap } - + if dec.RPCReturnDataLimit != nil { + c.RPCReturnDataLimit = *dec.RPCReturnDataLimit + } if dec.RPCEVMTimeout != nil { c.RPCEVMTimeout = *dec.RPCEVMTimeout } - if dec.RPCTxFeeCap != nil { c.RPCTxFeeCap = *dec.RPCTxFeeCap } - if dec.Checkpoint != nil { c.Checkpoint = dec.Checkpoint } - if dec.CheckpointOracle != nil { c.CheckpointOracle = dec.CheckpointOracle } - // TODO marcello double check if dec.OverrideShanghai != nil { c.OverrideShanghai = dec.OverrideShanghai } - + if dec.HeimdallURL != nil { + c.HeimdallURL = *dec.HeimdallURL + } + if dec.WithoutHeimdall != nil { + c.WithoutHeimdall = *dec.WithoutHeimdall + } + if dec.HeimdallgRPCAddress != nil { + c.HeimdallgRPCAddress = *dec.HeimdallgRPCAddress + } + if dec.RunHeimdall != nil { + c.RunHeimdall = *dec.RunHeimdall + } + if dec.RunHeimdallArgs != nil { + c.RunHeimdallArgs = *dec.RunHeimdallArgs + } + if dec.UseHeimdallApp != nil { + c.UseHeimdallApp = *dec.UseHeimdallApp + } + if dec.BorLogs != nil { + c.BorLogs = *dec.BorLogs + } + if dec.ParallelEVM != nil { + c.ParallelEVM = *dec.ParallelEVM + } + if dec.DevFakeAuthor != nil { + c.DevFakeAuthor = *dec.DevFakeAuthor + } return nil } diff --git a/eth/filters/filter.go b/eth/filters/filter.go index c0c5694cff..d256c3b222 100644 --- a/eth/filters/filter.go +++ b/eth/filters/filter.go @@ -328,6 +328,9 @@ func (f *Filter) checkMatches(ctx context.Context, header *types.Header) ([]*typ // pendingLogs returns the logs matching the filter criteria within the pending block. func (f *Filter) pendingLogs() ([]*types.Log, error) { block, receipts := f.sys.backend.PendingBlockAndReceipts() + if block == nil || receipts == nil { + return nil, errors.New("pending block is not available") + } if bloomFilter(block.Bloom(), f.addresses, f.topics) { var unfiltered []*types.Log for _, r := range receipts { diff --git a/eth/protocols/eth/handler_test.go b/eth/protocols/eth/handler_test.go index 29e71a5d5a..c001ec07ce 100644 --- a/eth/protocols/eth/handler_test.go +++ b/eth/protocols/eth/handler_test.go @@ -74,7 +74,6 @@ func newTestBackendWithGenerator(blocks int, shanghai bool, generator func(int, engine consensus.Engine = ethash.NewFaker() ) - // TODO marcello double check if shanghai { config = ¶ms.ChainConfig{ ChainID: big.NewInt(1), @@ -94,7 +93,7 @@ func newTestBackendWithGenerator(blocks int, shanghai bool, generator func(int, ArrowGlacierBlock: big.NewInt(0), GrayGlacierBlock: big.NewInt(0), MergeNetsplitBlock: big.NewInt(0), - ShanghaiTime: u64(0), + ShanghaiBlock: big.NewInt(0), TerminalTotalDifficulty: big.NewInt(0), TerminalTotalDifficultyPassed: true, Ethash: new(params.EthashConfig), @@ -368,11 +367,7 @@ func TestGetBlockBodies68(t *testing.T) { func testGetBlockBodies(t *testing.T, protocol uint) { gen := func(n int, g *core.BlockGen) { if n%2 == 0 { - w := &types.Withdrawal{ - Address: common.Address{0xaa}, - Amount: 42, - } - g.AddWithdrawal(w) + g.AddWithdrawal(&types.Withdrawal{}) } } diff --git a/eth/tracers/api.go b/eth/tracers/api.go index fb20d52e19..532347f90e 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -1425,18 +1425,18 @@ func overrideConfig(original *params.ChainConfig, override *params.ChainConfig) canon = false } - if timestamp := override.ShanghaiTime; timestamp != nil { - chainConfigCopy.ShanghaiTime = timestamp + if timestamp := override.ShanghaiBlock; timestamp != nil { + chainConfigCopy.ShanghaiBlock = timestamp canon = false } - if timestamp := override.CancunTime; timestamp != nil { - chainConfigCopy.CancunTime = timestamp + if timestamp := override.CancunBlock; timestamp != nil { + chainConfigCopy.CancunBlock = timestamp canon = false } - if timestamp := override.PragueTime; timestamp != nil { - chainConfigCopy.PragueTime = timestamp + if timestamp := override.PragueBlock; timestamp != nil { + chainConfigCopy.PragueBlock = timestamp canon = false } diff --git a/go.mod b/go.mod index f16c476c74..3305e033a8 100644 --- a/go.mod +++ b/go.mod @@ -180,6 +180,7 @@ require ( github.com/bgentry/speakeasy v0.1.0 // indirect github.com/bits-and-blooms/bitset v1.7.0 // indirect github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b // indirect + github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 // indirect github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce // indirect github.com/cbergoon/merkletree v0.2.0 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect @@ -238,6 +239,7 @@ require ( golang.org/x/oauth2 v0.10.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect + gotest.tools/v3 v3.5.1 // indirect ) require ( @@ -259,13 +261,13 @@ require ( google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98 // indirect ) -replace github.com/cosmos/cosmos-sdk => github.com/maticnetwork/cosmos-sdk v0.37.5-0.20231005133937-b1eb1f90feb7 +replace github.com/cosmos/cosmos-sdk => github.com/maticnetwork/cosmos-sdk v0.38.4 -replace github.com/tendermint/tendermint => github.com/maticnetwork/tendermint v0.26.0-dev0.0.20231005133805-2bb6a831bb2e +replace github.com/tendermint/tendermint => github.com/maticnetwork/tendermint v0.33.0 replace github.com/tendermint/tm-db => github.com/tendermint/tm-db v0.2.0 -replace github.com/ethereum/go-ethereum => github.com/maticnetwork/bor v1.0.4 +replace github.com/ethereum/go-ethereum => github.com/maticnetwork/bor v1.0.6 replace github.com/Masterminds/goutils => github.com/Masterminds/goutils v1.1.1 diff --git a/go.sum b/go.sum index b466e1cf66..e05509c81e 100644 --- a/go.sum +++ b/go.sum @@ -826,17 +826,13 @@ github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/ github.com/aws/aws-sdk-go v1.40.45 h1:QN1nsY27ssD/JmW4s83qmSb+uL6DG4GmCDzjmJB4xUI= github.com/aws/aws-sdk-go v1.40.45/go.mod h1:585smgzpB/KqRA+K3y/NL/oYRqQvpNJYvLm+LY1U59Q= github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= -github.com/aws/aws-sdk-go-v2 v1.2.0/go.mod h1:zEQs02YRBw1DjK0PoJv3ygDYOFTre1ejlJWl8FwAuQo= github.com/aws/aws-sdk-go-v2 v1.9.1/go.mod h1:cK/D0BBs0b/oWPIcX/Z/obahJK1TT7IPVjy53i/mX/4= github.com/aws/aws-sdk-go-v2 v1.21.0 h1:gMT0IW+03wtYJhRqTVYn0wLzwdnK9sRMcxmtfGzRdJc= github.com/aws/aws-sdk-go-v2 v1.21.0/go.mod h1:/RfNgGmRxI+iFOB1OeJUyxiU+9s88k3pfHvDagGEp0M= -github.com/aws/aws-sdk-go-v2/config v1.1.1/go.mod h1:0XsVy9lBI/BCXm+2Tuvt39YmdHwS5unDQmxZOYe8F5Y= github.com/aws/aws-sdk-go-v2/config v1.18.43 h1:IgdUtTRvUDC6eiJBqU6vh7bHFNAEBjQ8S+qJ7zVhDOs= github.com/aws/aws-sdk-go-v2/config v1.18.43/go.mod h1:NiFev8qlgg8MPzw3fO/EwzMZeZwlJEKGwfpjRPA9Nvw= -github.com/aws/aws-sdk-go-v2/credentials v1.1.1/go.mod h1:mM2iIjwl7LULWtS6JCACyInboHirisUUdkBPoTHMOUo= github.com/aws/aws-sdk-go-v2/credentials v1.13.41 h1:dgbKq1tamtboYAKSXWbqL0lKO9rmEzEhbZFh9JQW/Bg= github.com/aws/aws-sdk-go-v2/credentials v1.13.41/go.mod h1:cc3Fn7DkKbJalPtQnudHGZZ8ml9+hwtbc1CJONsYYqk= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.0.2/go.mod h1:3hGg3PpiEjHnrkrlasTfxFqUsZ2GCk/fMUn4CbKgSkM= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.11 h1:uDZJF1hu0EVT/4bogChk8DyjSF6fof6uL/0Y26Ma7Fg= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.11/go.mod h1:TEPP4tENqBGO99KwVpV9MlOX4NSrSLP8u3KRy2CDwA8= github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.41 h1:22dGT7PneFMx4+b3pz7lMTRyN8ZKH7M2cW4GP9yUS2g= @@ -846,21 +842,16 @@ github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.35/go.mod h1:SJC1nEVVva1 github.com/aws/aws-sdk-go-v2/internal/ini v1.3.43 h1:g+qlObJH4Kn4n21g69DjspU0hKTjWtq7naZ9OLCv0ew= github.com/aws/aws-sdk-go-v2/internal/ini v1.3.43/go.mod h1:rzfdUlfA+jdgLDmPKjd3Chq9V7LVLYo1Nz++Wb91aRo= github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.8.1/go.mod h1:CM+19rL1+4dFWnOQKwDc7H1KwXTz+h61oUSHyhV0b3o= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.0.2/go.mod h1:45MfaXZ0cNbeuT0KQ1XJylq8A6+OpVV2E5kvY/Kq+u8= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.35 h1:CdzPW9kKitgIiLV1+MHobfR5Xg25iYnyzWZhyQuSlDI= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.35/go.mod h1:QGF2Rs33W5MaN9gYdEQOBBFPLwTZkEhRwI33f7KIG0o= -github.com/aws/aws-sdk-go-v2/service/route53 v1.1.1/go.mod h1:rLiOUrPLW/Er5kRcQ7NkwbjlijluLsrIbu/iyl35RO4= github.com/aws/aws-sdk-go-v2/service/route53 v1.29.5 h1:6wPin3WPyQpBl/QZsoNUnqvXy4Ib1Ygv7VagGvLKJAc= github.com/aws/aws-sdk-go-v2/service/route53 v1.29.5/go.mod h1:6zl0jh5MUKuJ07eHn3MNeLOVutxwl8m9vQltZjoLakM= -github.com/aws/aws-sdk-go-v2/service/sso v1.1.1/go.mod h1:SuZJxklHxLAXgLTc1iFXbEWkXs7QRTQpCLGaKIprQW0= github.com/aws/aws-sdk-go-v2/service/sso v1.15.0 h1:vuGK1vHNP9zx0PfOrtPumbwR2af0ATQ1Z2H6p75AgRQ= github.com/aws/aws-sdk-go-v2/service/sso v1.15.0/go.mod h1:fIAwKQKBFu90pBxx07BFOMJLpRUGu8VOzLJakeY+0K4= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.1 h1:8lKOidPkmSmfUtiTgtdXWgaKItCZ/g75/jEk6Ql6GsA= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.1/go.mod h1:yygr8ACQRY2PrEcy3xsUI357stq2AxnFM6DIsR9lij4= -github.com/aws/aws-sdk-go-v2/service/sts v1.1.1/go.mod h1:Wi0EBZwiz/K44YliU0EKxqTCJGUfYTWXrrBwkq736bM= github.com/aws/aws-sdk-go-v2/service/sts v1.23.0 h1:pyvfUqkNLMipdKNAtu7OVbRxUrR2BMaKccIPpk/Hkak= github.com/aws/aws-sdk-go-v2/service/sts v1.23.0/go.mod h1:VC7JDqsqiwXukYEDjoHh9U0fOJtNWh04FPQz4ct4GGU= -github.com/aws/smithy-go v1.1.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB9LgIw= github.com/aws/smithy-go v1.8.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E= github.com/aws/smithy-go v1.14.2 h1:MJU9hqBGbvWZdApzpvoF2WAIJDbtjK2NDJSiJP7HblQ= github.com/aws/smithy-go v1.14.2/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= @@ -886,15 +877,14 @@ github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b/go.mod h1:H0wQ github.com/btcsuite/btcd v0.0.0-20190115013929-ed77733ec07d/go.mod h1:d3C0AkH6BRcvO8T0UEPu53cnw4IbV63x1bEjildYhO0= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btcd v0.22.0-beta/go.mod h1:9n5ntfhhHQBIhUvlhDvD3Qg6fRUj4jkN0VB8L8svzOA= -github.com/btcsuite/btcd v0.22.3 h1:kYNaWFvOw6xvqP0vR20RP1Zq1DVMBxEO8QN5d1/EfNg= -github.com/btcsuite/btcd v0.22.3/go.mod h1:wqgTSL29+50LRkmOVknEdmt8ZojIzhuWvgu/iptuN7Y= github.com/btcsuite/btcd/btcec/v2 v2.1.2/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE= github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU= github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= -github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 h1:KdUfX2zKommPRa+PD0sWZUyXe9w277ABlgELO7H04IM= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20180706230648-ab6388e0c60a/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= @@ -973,7 +963,6 @@ github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= -github.com/consensys/gnark-crypto v0.9.1-0.20230105202408-1a7a29904a7c/go.mod h1:CkbdF9hbRidRJYMRzmfX8TMOr95I2pYXRHF18MzRrvA= github.com/consensys/gnark-crypto v0.12.0 h1:1OnSpOykNkUIBIBJKdhwy2p0JlW5o+Az02ICzZmvvdg= github.com/consensys/gnark-crypto v0.12.0/go.mod h1:v2Gy7L/4ZRosZ7Ivs+9SfUDr0f5UlG+EM5t7MPHiLuY= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= @@ -1632,17 +1621,17 @@ github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE= github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0= -github.com/maticnetwork/bor v1.0.4/go.mod h1:HzDbqdJMBJMIF7b3yxaeWGU6vEIrCZkIouGhJ1q3Ybc= -github.com/maticnetwork/cosmos-sdk v0.37.5-0.20231005133937-b1eb1f90feb7 h1:6U6WvtWQHUxzNqlo2UkcdmPfEIoyYg+c08j31nCgRZg= -github.com/maticnetwork/cosmos-sdk v0.37.5-0.20231005133937-b1eb1f90feb7/go.mod h1:N3NySXu6ob1GKEJSUwp3vE2Ri9G1vzk0T0tNGodTBoU= +github.com/maticnetwork/bor v1.0.6/go.mod h1:G6yfIs9dMYF0hP7BdhEFtCjpUEYqXBag+q/Uit4cqmQ= +github.com/maticnetwork/cosmos-sdk v0.38.4 h1:PAfkMXzHDHJoAf4bXQL4UWgwbu/U3yYuXoXxPhXdpBw= +github.com/maticnetwork/cosmos-sdk v0.38.4/go.mod h1:NbuVdUoqlRF6RrFJp27hpbqSoRB8cJJfUxCzUJWtaLA= github.com/maticnetwork/crand v1.0.2 h1:Af0tAivC8zrxXDpGWNWVT/0s1fOz8w0eRbahZgURS8I= github.com/maticnetwork/crand v1.0.2/go.mod h1:/NRNL3bj2eYdqpWmoIP5puxndTpi0XRxpj5ZKxfHjyg= github.com/maticnetwork/heimdall v0.3.1-0.20230227104835-81bd1055b0bc h1:7wEWQbYs6ESGsVBhjiVp7fZZyfaN4lg4XYLOLfRIpmY= github.com/maticnetwork/heimdall v0.3.1-0.20230227104835-81bd1055b0bc/go.mod h1:P2DoKhovYP9G9Kj2EH/zHaiRJF1jNU7ZJOyelG4UCa8= github.com/maticnetwork/polyproto v0.0.3-0.20230216113155-340ea926ca53 h1:PjYV+lghs106JKkrYgOnrsfDLoTc11BxZd4rUa4Rus4= github.com/maticnetwork/polyproto v0.0.3-0.20230216113155-340ea926ca53/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o= -github.com/maticnetwork/tendermint v0.26.0-dev0.0.20231005133805-2bb6a831bb2e h1:gvjyv7uPmtfWe4mX+7Bmy02Ftal2Mfoadf+dXxGVBYI= -github.com/maticnetwork/tendermint v0.26.0-dev0.0.20231005133805-2bb6a831bb2e/go.mod h1:D2fcnxGk6bje+LoPwImuKSSYLiK7/G06IynGNDSEcJk= +github.com/maticnetwork/tendermint v0.33.0 h1:f+vORM02BoUOlCvnu3Zjw5rv6l6JSNVchWjH03rUuR8= +github.com/maticnetwork/tendermint v0.33.0/go.mod h1:D2fcnxGk6bje+LoPwImuKSSYLiK7/G06IynGNDSEcJk= github.com/matryer/moq v0.0.0-20190312154309-6cfb0558e1bd/go.mod h1:9ELz6aaclSIGnZBoaSLZ3NAl1VTufbOrXBPvtcy6WiQ= github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2/go.mod h1:0KeJpeMD6o+O4hW7qJOT7vyQPKrWmj26uf5wMc/IiIs= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= @@ -2021,7 +2010,6 @@ github.com/stvp/tempredis v0.0.0-20181119212430-b82af8480203/go.mod h1:oqN97ltKN github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs= github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= -github.com/supranational/blst v0.3.8-0.20220526154634-513d2456b344/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4= github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/syndtr/goleveldb v1.0.1-0.20190318030020-c3a204f8e965/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA= @@ -2232,7 +2220,6 @@ golang.org/x/crypto v0.0.0-20220314234659-1baeb1ce4c0b/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220507011949-2cf3adece122/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= @@ -2598,6 +2585,7 @@ golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= @@ -3114,8 +3102,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= -gotest.tools/v3 v3.5.0 h1:Ljk6PdHdOhAb5aDMWXjDLMMhph+BpztA4v1QdqEW2eY= -gotest.tools/v3 v3.5.0/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= +gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= +gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/internal/cli/server/chains/mumbai.go b/internal/cli/server/chains/mumbai.go index 91fe0c440c..45f36fbe89 100644 --- a/internal/cli/server/chains/mumbai.go +++ b/internal/cli/server/chains/mumbai.go @@ -27,6 +27,7 @@ var mumbaiTestnet = &Chain{ MuirGlacierBlock: big.NewInt(2722000), BerlinBlock: big.NewInt(13996000), LondonBlock: big.NewInt(22640000), + ShanghaiBlock: big.NewInt(41874000), Bor: ¶ms.BorConfig{ JaipurBlock: big.NewInt(22770000), DelhiBlock: big.NewInt(29638656), @@ -57,6 +58,7 @@ var mumbaiTestnet = &Chain{ StateReceiverContract: "0x0000000000000000000000000000000000001001", BurntContract: map[string]string{ "22640000": "0x70bcA57F4579f58670aB2d18Ef16e02C17553C38", + "41874000": "0x617b94CCCC2511808A3C9478ebb96f455CF167aA", }, BlockAlloc: map[string]interface{}{ // write as interface since that is how it is decoded in genesis @@ -66,6 +68,12 @@ var mumbaiTestnet = &Chain{ "code": "0x60806040526004361061019c5760003560e01c806377d32e94116100ec578063acd06cb31161008a578063e306f77911610064578063e306f77914610a7b578063e614d0d614610aa6578063f2fde38b14610ad1578063fc0c546a14610b225761019c565b8063acd06cb31461097a578063b789543c146109cd578063cc79f97b14610a505761019c565b80639025e64c116100c65780639025e64c146107c957806395d89b4114610859578063a9059cbb146108e9578063abceeba21461094f5761019c565b806377d32e94146106315780638da5cb5b146107435780638f32d59b1461079a5761019c565b806347e7ef24116101595780637019d41a116101335780637019d41a1461053357806370a082311461058a578063715018a6146105ef578063771282f6146106065761019c565b806347e7ef2414610410578063485cc9551461046b57806360f96a8f146104dc5761019c565b806306fdde03146101a15780631499c5921461023157806318160ddd1461028257806319d27d9c146102ad5780632e1a7d4d146103b1578063313ce567146103df575b600080fd5b3480156101ad57600080fd5b506101b6610b79565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101f65780820151818401526020810190506101db565b50505050905090810190601f1680156102235780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561023d57600080fd5b506102806004803603602081101561025457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610bb6565b005b34801561028e57600080fd5b50610297610c24565b6040518082815260200191505060405180910390f35b3480156102b957600080fd5b5061036f600480360360a08110156102d057600080fd5b81019080803590602001906401000000008111156102ed57600080fd5b8201836020820111156102ff57600080fd5b8035906020019184600183028401116401000000008311171561032157600080fd5b9091929391929390803590602001909291908035906020019092919080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610c3a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6103dd600480360360208110156103c757600080fd5b8101908080359060200190929190505050610caa565b005b3480156103eb57600080fd5b506103f4610dfc565b604051808260ff1660ff16815260200191505060405180910390f35b34801561041c57600080fd5b506104696004803603604081101561043357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610e05565b005b34801561047757600080fd5b506104da6004803603604081101561048e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610fc1565b005b3480156104e857600080fd5b506104f1611090565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561053f57600080fd5b506105486110b6565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561059657600080fd5b506105d9600480360360208110156105ad57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506110dc565b6040518082815260200191505060405180910390f35b3480156105fb57600080fd5b506106046110fd565b005b34801561061257600080fd5b5061061b6111cd565b6040518082815260200191505060405180910390f35b34801561063d57600080fd5b506107016004803603604081101561065457600080fd5b81019080803590602001909291908035906020019064010000000081111561067b57600080fd5b82018360208201111561068d57600080fd5b803590602001918460018302840111640100000000831117156106af57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506111d3565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561074f57600080fd5b50610758611358565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156107a657600080fd5b506107af611381565b604051808215151515815260200191505060405180910390f35b3480156107d557600080fd5b506107de6113d8565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561081e578082015181840152602081019050610803565b50505050905090810190601f16801561084b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561086557600080fd5b5061086e611411565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156108ae578082015181840152602081019050610893565b50505050905090810190601f1680156108db5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610935600480360360408110156108ff57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061144e565b604051808215151515815260200191505060405180910390f35b34801561095b57600080fd5b50610964611474565b6040518082815260200191505060405180910390f35b34801561098657600080fd5b506109b36004803603602081101561099d57600080fd5b8101908080359060200190929190505050611501565b604051808215151515815260200191505060405180910390f35b3480156109d957600080fd5b50610a3a600480360360808110156109f057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291908035906020019092919080359060200190929190505050611521565b6040518082815260200191505060405180910390f35b348015610a5c57600080fd5b50610a65611541565b6040518082815260200191505060405180910390f35b348015610a8757600080fd5b50610a90611548565b6040518082815260200191505060405180910390f35b348015610ab257600080fd5b50610abb61154e565b6040518082815260200191505060405180910390f35b348015610add57600080fd5b50610b2060048036036020811015610af457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506115db565b005b348015610b2e57600080fd5b50610b376115f8565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b60606040518060400160405280600b81526020017f4d6174696320546f6b656e000000000000000000000000000000000000000000815250905090565b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260108152602001807f44697361626c656420666561747572650000000000000000000000000000000081525060200191505060405180910390fd5b6000601260ff16600a0a6402540be40002905090565b60006040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260108152602001807f44697361626c656420666561747572650000000000000000000000000000000081525060200191505060405180910390fd5b60003390506000610cba826110dc565b9050610cd18360065461161e90919063ffffffff16565b600681905550600083118015610ce657508234145b610d58576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f496e73756666696369656e7420616d6f756e740000000000000000000000000081525060200191505060405180910390fd5b8173ffffffffffffffffffffffffffffffffffffffff16600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167febff2602b3f468259e1e99f613fed6691f3a6526effe6ef3e768ba7ae7a36c4f8584610dd4876110dc565b60405180848152602001838152602001828152602001935050505060405180910390a3505050565b60006012905090565b610e0d611381565b610e1657600080fd5b600081118015610e535750600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b610ea8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180611da96023913960400191505060405180910390fd5b6000610eb3836110dc565b905060008390508073ffffffffffffffffffffffffffffffffffffffff166108fc849081150290604051600060405180830381858888f19350505050158015610f00573d6000803e3d6000fd5b50610f168360065461163e90919063ffffffff16565b6006819055508373ffffffffffffffffffffffffffffffffffffffff16600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f4e2ca0515ed1aef1395f66b5303bb5d6f1bf9d61a353fa53f73f8ac9973fa9f68585610f98896110dc565b60405180848152602001838152602001828152602001935050505060405180910390a350505050565b600760009054906101000a900460ff1615611027576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180611d866023913960400191505060405180910390fd5b6001600760006101000a81548160ff02191690831515021790555080600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555061108c8261165d565b5050565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008173ffffffffffffffffffffffffffffffffffffffff16319050919050565b611105611381565b61110e57600080fd5b600073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60065481565b60008060008060418551146111ee5760009350505050611352565b602085015192506040850151915060ff6041860151169050601b8160ff16101561121957601b810190505b601b8160ff16141580156112315750601c8160ff1614155b156112425760009350505050611352565b60018682858560405160008152602001604052604051808581526020018460ff1660ff1681526020018381526020018281526020019450505050506020604051602081039080840390855afa15801561129f573d6000803e3d6000fd5b505050602060405103519350600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16141561134e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f4572726f7220696e2065637265636f766572000000000000000000000000000081525060200191505060405180910390fd5b5050505b92915050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614905090565b6040518060400160405280600381526020017f013881000000000000000000000000000000000000000000000000000000000081525081565b60606040518060400160405280600581526020017f4d41544943000000000000000000000000000000000000000000000000000000815250905090565b6000813414611460576000905061146e565b61146b338484611755565b90505b92915050565b6040518060800160405280605b8152602001611e1e605b91396040516020018082805190602001908083835b602083106114c357805182526020820191506020810190506020830392506114a0565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040516020818303038152906040528051906020012081565b60056020528060005260406000206000915054906101000a900460ff1681565b600061153761153286868686611b12565b611be8565b9050949350505050565b6201388181565b60015481565b604051806080016040528060528152602001611dcc605291396040516020018082805190602001908083835b6020831061159d578051825260208201915060208101905060208303925061157a565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040516020818303038152906040528051906020012081565b6115e3611381565b6115ec57600080fd5b6115f58161165d565b50565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008282111561162d57600080fd5b600082840390508091505092915050565b60008082840190508381101561165357600080fd5b8091505092915050565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561169757600080fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000803073ffffffffffffffffffffffffffffffffffffffff166370a08231866040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b1580156117d557600080fd5b505afa1580156117e9573d6000803e3d6000fd5b505050506040513d60208110156117ff57600080fd5b8101908080519060200190929190505050905060003073ffffffffffffffffffffffffffffffffffffffff166370a08231866040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b15801561189157600080fd5b505afa1580156118a5573d6000803e3d6000fd5b505050506040513d60208110156118bb57600080fd5b810190808051906020019092919050505090506118d9868686611c32565b8473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff16600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fe6497e3ee548a3372136af2fcb0696db31fc6cf20260707645068bd3fe97f3c48786863073ffffffffffffffffffffffffffffffffffffffff166370a082318e6040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b1580156119e157600080fd5b505afa1580156119f5573d6000803e3d6000fd5b505050506040513d6020811015611a0b57600080fd5b81019080805190602001909291905050503073ffffffffffffffffffffffffffffffffffffffff166370a082318e6040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015611a9957600080fd5b505afa158015611aad573d6000803e3d6000fd5b505050506040513d6020811015611ac357600080fd5b8101908080519060200190929190505050604051808681526020018581526020018481526020018381526020018281526020019550505050505060405180910390a46001925050509392505050565b6000806040518060800160405280605b8152602001611e1e605b91396040516020018082805190602001908083835b60208310611b645780518252602082019150602081019050602083039250611b41565b6001836020036101000a03801982511681845116808217855250505050505090500191505060405160208183030381529060405280519060200120905060405181815273ffffffffffffffffffffffffffffffffffffffff8716602082015285604082015284606082015283608082015260a0812092505081915050949350505050565b60008060015490506040517f190100000000000000000000000000000000000000000000000000000000000081528160028201528360228201526042812092505081915050919050565b3073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611cd4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f63616e27742073656e6420746f204d524332300000000000000000000000000081525060200191505060405180910390fd5b8173ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f19350505050158015611d1a573d6000803e3d6000fd5b508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a350505056fe54686520636f6e747261637420697320616c726561647920696e697469616c697a6564496e73756666696369656e7420616d6f756e74206f7220696e76616c69642075736572454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c75696e7432353620636861696e49642c6164647265737320766572696679696e67436f6e747261637429546f6b656e5472616e736665724f726465722861646472657373207370656e6465722c75696e7432353620746f6b656e49644f72416d6f756e742c6279746573333220646174612c75696e743235362065787069726174696f6e29a265627a7a72315820ccd6c2a9c259832bbb367986ee06cd87af23022681b0cb22311a864b701d939564736f6c63430005100032", }, }, + "41874000": map[string]interface{}{ + "0x0000000000000000000000000000000000001001": map[string]interface{}{ + "balance": "0x0", + "code": "0x608060405234801561001057600080fd5b506004361061005e576000357c01000000000000000000000000000000000000000000000000000000009004806319494a17146100635780633434735f146100fe5780635407ca6714610148575b600080fd5b6100e46004803603604081101561007957600080fd5b8101908080359060200190929190803590602001906401000000008111156100a057600080fd5b8201836020820111156100b257600080fd5b803590602001918460018302840111640100000000831117156100d457600080fd5b9091929391929390505050610166565b604051808215151515815260200191505060405180910390f35b6101066104d3565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6101506104eb565b6040518082815260200191505060405180910390f35b600073fffffffffffffffffffffffffffffffffffffffe73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461021d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f4e6f742053797374656d2041646465737321000000000000000000000000000081525060200191505060405180910390fd5b606061027461026f85858080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050506104f1565b61051f565b905060006102958260008151811061028857fe5b60200260200101516105fc565b90508060016000540114610311576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f537461746549647320617265206e6f742073657175656e7469616c000000000081525060200191505060405180910390fd5b600080815480929190600101919050555060006103418360018151811061033457fe5b602002602001015161066d565b905060606103628460028151811061035557fe5b6020026020010151610690565b905061036d8261071c565b156104c8576000624c4b409050606084836040516024018083815260200180602001828103825283818151815260200191508051906020019080838360005b838110156103c75780820151818401526020810190506103ac565b50505050905090810190601f1680156103f45780820380516001836020036101000a031916815260200191505b5093505050506040516020818303038152906040527f26c53bea000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050905060008082516020840160008887f19650847f5a22725590b0a51c923940223f7458512164b1113359a735e86e7f27f44791ee88604051808215151515815260200191505060405180910390a250505b505050509392505050565b73fffffffffffffffffffffffffffffffffffffffe81565b60005481565b6104f961099c565b600060208301905060405180604001604052808451815260200182815250915050919050565b606061052a82610735565b61053357600080fd5b600061053e83610783565b905060608160405190808252806020026020018201604052801561057c57816020015b6105696109b6565b8152602001906001900390816105615790505b509050600061058e85602001516107f4565b8560200151019050600080600090505b848110156105ef576105af8361087d565b91506040518060400160405280838152602001848152508482815181106105d257fe5b60200260200101819052508183019250808060010191505061059e565b5082945050505050919050565b600080826000015111801561061657506021826000015111155b61061f57600080fd5b600061062e83602001516107f4565b9050600081846000015103905060008083866020015101905080519150602083101561066157826020036101000a820491505b81945050505050919050565b6000601582600001511461068057600080fd5b610689826105fc565b9050919050565b606060008260000151116106a357600080fd5b60006106b283602001516107f4565b905060008184600001510390506060816040519080825280601f01601f1916602001820160405280156106f45781602001600182028038833980820191505090505b5090506000816020019050610710848760200151018285610935565b81945050505050919050565b600080823b905060008163ffffffff1611915050919050565b6000808260000151141561074c576000905061077e565b60008083602001519050805160001a915060c060ff168260ff1610156107775760009250505061077e565b6001925050505b919050565b6000808260000151141561079a57600090506107ef565b600080905060006107ae84602001516107f4565b84602001510190506000846000015185602001510190505b808210156107e8576107d78261087d565b8201915082806001019350506107c6565b8293505050505b919050565b600080825160001a9050608060ff16811015610814576000915050610878565b60b860ff16811080610839575060c060ff168110158015610838575060f860ff1681105b5b15610848576001915050610878565b60c060ff168110156108685760018060b80360ff16820301915050610878565b60018060f80360ff168203019150505b919050565b6000806000835160001a9050608060ff1681101561089e576001915061092b565b60b860ff168110156108bb576001608060ff16820301915061092a565b60c060ff168110156108eb5760b78103600185019450806020036101000a85510460018201810193505050610929565b60f860ff1681101561090857600160c060ff168203019150610928565b60f78103600185019450806020036101000a855104600182018101935050505b5b5b5b8192505050919050565b600081141561094357610997565b5b602060ff1681106109735782518252602060ff1683019250602060ff1682019150602060ff1681039050610944565b6000600182602060ff16036101000a03905080198451168184511681811785525050505b505050565b604051806040016040528060008152602001600081525090565b60405180604001604052806000815260200160008152509056fea265627a7a723158208f1ea6fcf63d6911ac5dbfe340be1029614581802c6a750e7d6354b32ce6647c64736f6c63430005110032", + }, + }, }, }, }, diff --git a/internal/cli/server/chains/test_files/chain_legacy_test.json b/internal/cli/server/chains/test_files/chain_legacy_test.json index a9f6a0923a..a64fbf3e23 100644 --- a/internal/cli/server/chains/test_files/chain_legacy_test.json +++ b/internal/cli/server/chains/test_files/chain_legacy_test.json @@ -14,6 +14,7 @@ "muirGlacierBlock": 2722000, "berlinBlock": 13996000, "londonBlock": 13996000, + "shanghaiBlock": 41874000, "bor": { "period": { "0": 2, @@ -42,10 +43,17 @@ "balance": "0x0", "code": "0x60806040526004361061019c5760003560e01c806377d32e94116100ec578063acd06cb31161008a578063e306f77911610064578063e306f77914610a7b578063e614d0d614610aa6578063f2fde38b14610ad1578063fc0c546a14610b225761019c565b8063acd06cb31461097a578063b789543c146109cd578063cc79f97b14610a505761019c565b80639025e64c116100c65780639025e64c146107c957806395d89b4114610859578063a9059cbb146108e9578063abceeba21461094f5761019c565b806377d32e94146106315780638da5cb5b146107435780638f32d59b1461079a5761019c565b806347e7ef24116101595780637019d41a116101335780637019d41a1461053357806370a082311461058a578063715018a6146105ef578063771282f6146106065761019c565b806347e7ef2414610410578063485cc9551461046b57806360f96a8f146104dc5761019c565b806306fdde03146101a15780631499c5921461023157806318160ddd1461028257806319d27d9c146102ad5780632e1a7d4d146103b1578063313ce567146103df575b600080fd5b3480156101ad57600080fd5b506101b6610b79565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101f65780820151818401526020810190506101db565b50505050905090810190601f1680156102235780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561023d57600080fd5b506102806004803603602081101561025457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610bb6565b005b34801561028e57600080fd5b50610297610c24565b6040518082815260200191505060405180910390f35b3480156102b957600080fd5b5061036f600480360360a08110156102d057600080fd5b81019080803590602001906401000000008111156102ed57600080fd5b8201836020820111156102ff57600080fd5b8035906020019184600183028401116401000000008311171561032157600080fd5b9091929391929390803590602001909291908035906020019092919080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610c3a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6103dd600480360360208110156103c757600080fd5b8101908080359060200190929190505050610caa565b005b3480156103eb57600080fd5b506103f4610dfc565b604051808260ff1660ff16815260200191505060405180910390f35b34801561041c57600080fd5b506104696004803603604081101561043357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610e05565b005b34801561047757600080fd5b506104da6004803603604081101561048e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610fc1565b005b3480156104e857600080fd5b506104f1611090565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561053f57600080fd5b506105486110b6565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561059657600080fd5b506105d9600480360360208110156105ad57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506110dc565b6040518082815260200191505060405180910390f35b3480156105fb57600080fd5b506106046110fd565b005b34801561061257600080fd5b5061061b6111cd565b6040518082815260200191505060405180910390f35b34801561063d57600080fd5b506107016004803603604081101561065457600080fd5b81019080803590602001909291908035906020019064010000000081111561067b57600080fd5b82018360208201111561068d57600080fd5b803590602001918460018302840111640100000000831117156106af57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506111d3565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561074f57600080fd5b50610758611358565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156107a657600080fd5b506107af611381565b604051808215151515815260200191505060405180910390f35b3480156107d557600080fd5b506107de6113d8565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561081e578082015181840152602081019050610803565b50505050905090810190601f16801561084b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561086557600080fd5b5061086e611411565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156108ae578082015181840152602081019050610893565b50505050905090810190601f1680156108db5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610935600480360360408110156108ff57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061144e565b604051808215151515815260200191505060405180910390f35b34801561095b57600080fd5b50610964611474565b6040518082815260200191505060405180910390f35b34801561098657600080fd5b506109b36004803603602081101561099d57600080fd5b8101908080359060200190929190505050611501565b604051808215151515815260200191505060405180910390f35b3480156109d957600080fd5b50610a3a600480360360808110156109f057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291908035906020019092919080359060200190929190505050611521565b6040518082815260200191505060405180910390f35b348015610a5c57600080fd5b50610a65611541565b6040518082815260200191505060405180910390f35b348015610a8757600080fd5b50610a90611548565b6040518082815260200191505060405180910390f35b348015610ab257600080fd5b50610abb61154e565b6040518082815260200191505060405180910390f35b348015610add57600080fd5b50610b2060048036036020811015610af457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506115db565b005b348015610b2e57600080fd5b50610b376115f8565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b60606040518060400160405280600b81526020017f4d6174696320546f6b656e000000000000000000000000000000000000000000815250905090565b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260108152602001807f44697361626c656420666561747572650000000000000000000000000000000081525060200191505060405180910390fd5b6000601260ff16600a0a6402540be40002905090565b60006040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260108152602001807f44697361626c656420666561747572650000000000000000000000000000000081525060200191505060405180910390fd5b60003390506000610cba826110dc565b9050610cd18360065461161e90919063ffffffff16565b600681905550600083118015610ce657508234145b610d58576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f496e73756666696369656e7420616d6f756e740000000000000000000000000081525060200191505060405180910390fd5b8173ffffffffffffffffffffffffffffffffffffffff16600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167febff2602b3f468259e1e99f613fed6691f3a6526effe6ef3e768ba7ae7a36c4f8584610dd4876110dc565b60405180848152602001838152602001828152602001935050505060405180910390a3505050565b60006012905090565b610e0d611381565b610e1657600080fd5b600081118015610e535750600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b610ea8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180611da96023913960400191505060405180910390fd5b6000610eb3836110dc565b905060008390508073ffffffffffffffffffffffffffffffffffffffff166108fc849081150290604051600060405180830381858888f19350505050158015610f00573d6000803e3d6000fd5b50610f168360065461163e90919063ffffffff16565b6006819055508373ffffffffffffffffffffffffffffffffffffffff16600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f4e2ca0515ed1aef1395f66b5303bb5d6f1bf9d61a353fa53f73f8ac9973fa9f68585610f98896110dc565b60405180848152602001838152602001828152602001935050505060405180910390a350505050565b600760009054906101000a900460ff1615611027576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180611d866023913960400191505060405180910390fd5b6001600760006101000a81548160ff02191690831515021790555080600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555061108c8261165d565b5050565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008173ffffffffffffffffffffffffffffffffffffffff16319050919050565b611105611381565b61110e57600080fd5b600073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60065481565b60008060008060418551146111ee5760009350505050611352565b602085015192506040850151915060ff6041860151169050601b8160ff16101561121957601b810190505b601b8160ff16141580156112315750601c8160ff1614155b156112425760009350505050611352565b60018682858560405160008152602001604052604051808581526020018460ff1660ff1681526020018381526020018281526020019450505050506020604051602081039080840390855afa15801561129f573d6000803e3d6000fd5b505050602060405103519350600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16141561134e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f4572726f7220696e2065637265636f766572000000000000000000000000000081525060200191505060405180910390fd5b5050505b92915050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614905090565b6040518060400160405280600381526020017f013881000000000000000000000000000000000000000000000000000000000081525081565b60606040518060400160405280600581526020017f4d41544943000000000000000000000000000000000000000000000000000000815250905090565b6000813414611460576000905061146e565b61146b338484611755565b90505b92915050565b6040518060800160405280605b8152602001611e1e605b91396040516020018082805190602001908083835b602083106114c357805182526020820191506020810190506020830392506114a0565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040516020818303038152906040528051906020012081565b60056020528060005260406000206000915054906101000a900460ff1681565b600061153761153286868686611b12565b611be8565b9050949350505050565b6201388181565b60015481565b604051806080016040528060528152602001611dcc605291396040516020018082805190602001908083835b6020831061159d578051825260208201915060208101905060208303925061157a565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040516020818303038152906040528051906020012081565b6115e3611381565b6115ec57600080fd5b6115f58161165d565b50565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008282111561162d57600080fd5b600082840390508091505092915050565b60008082840190508381101561165357600080fd5b8091505092915050565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561169757600080fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000803073ffffffffffffffffffffffffffffffffffffffff166370a08231866040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b1580156117d557600080fd5b505afa1580156117e9573d6000803e3d6000fd5b505050506040513d60208110156117ff57600080fd5b8101908080519060200190929190505050905060003073ffffffffffffffffffffffffffffffffffffffff166370a08231866040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b15801561189157600080fd5b505afa1580156118a5573d6000803e3d6000fd5b505050506040513d60208110156118bb57600080fd5b810190808051906020019092919050505090506118d9868686611c32565b8473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff16600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fe6497e3ee548a3372136af2fcb0696db31fc6cf20260707645068bd3fe97f3c48786863073ffffffffffffffffffffffffffffffffffffffff166370a082318e6040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b1580156119e157600080fd5b505afa1580156119f5573d6000803e3d6000fd5b505050506040513d6020811015611a0b57600080fd5b81019080805190602001909291905050503073ffffffffffffffffffffffffffffffffffffffff166370a082318e6040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015611a9957600080fd5b505afa158015611aad573d6000803e3d6000fd5b505050506040513d6020811015611ac357600080fd5b8101908080519060200190929190505050604051808681526020018581526020018481526020018381526020018281526020019550505050505060405180910390a46001925050509392505050565b6000806040518060800160405280605b8152602001611e1e605b91396040516020018082805190602001908083835b60208310611b645780518252602082019150602081019050602083039250611b41565b6001836020036101000a03801982511681845116808217855250505050505090500191505060405160208183030381529060405280519060200120905060405181815273ffffffffffffffffffffffffffffffffffffffff8716602082015285604082015284606082015283608082015260a0812092505081915050949350505050565b60008060015490506040517f190100000000000000000000000000000000000000000000000000000000000081528160028201528360228201526042812092505081915050919050565b3073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611cd4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f63616e27742073656e6420746f204d524332300000000000000000000000000081525060200191505060405180910390fd5b8173ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f19350505050158015611d1a573d6000803e3d6000fd5b508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a350505056fe54686520636f6e747261637420697320616c726561647920696e697469616c697a6564496e73756666696369656e7420616d6f756e74206f7220696e76616c69642075736572454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c75696e7432353620636861696e49642c6164647265737320766572696679696e67436f6e747261637429546f6b656e5472616e736665724f726465722861646472657373207370656e6465722c75696e7432353620746f6b656e49644f72416d6f756e742c6279746573333220646174612c75696e743235362065787069726174696f6e29a265627a7a72315820ccd6c2a9c259832bbb367986ee06cd87af23022681b0cb22311a864b701d939564736f6c63430005100032" } + }, + "41874000": { + "0x0000000000000000000000000000000000001001": { + "balance": "0x0", + "code": "0x608060405234801561001057600080fd5b506004361061005e576000357c01000000000000000000000000000000000000000000000000000000009004806319494a17146100635780633434735f146100fe5780635407ca6714610148575b600080fd5b6100e46004803603604081101561007957600080fd5b8101908080359060200190929190803590602001906401000000008111156100a057600080fd5b8201836020820111156100b257600080fd5b803590602001918460018302840111640100000000831117156100d457600080fd5b9091929391929390505050610166565b604051808215151515815260200191505060405180910390f35b6101066104d3565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6101506104eb565b6040518082815260200191505060405180910390f35b600073fffffffffffffffffffffffffffffffffffffffe73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461021d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f4e6f742053797374656d2041646465737321000000000000000000000000000081525060200191505060405180910390fd5b606061027461026f85858080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050506104f1565b61051f565b905060006102958260008151811061028857fe5b60200260200101516105fc565b90508060016000540114610311576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f537461746549647320617265206e6f742073657175656e7469616c000000000081525060200191505060405180910390fd5b600080815480929190600101919050555060006103418360018151811061033457fe5b602002602001015161066d565b905060606103628460028151811061035557fe5b6020026020010151610690565b905061036d8261071c565b156104c8576000624c4b409050606084836040516024018083815260200180602001828103825283818151815260200191508051906020019080838360005b838110156103c75780820151818401526020810190506103ac565b50505050905090810190601f1680156103f45780820380516001836020036101000a031916815260200191505b5093505050506040516020818303038152906040527f26c53bea000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050905060008082516020840160008887f19650847f5a22725590b0a51c923940223f7458512164b1113359a735e86e7f27f44791ee88604051808215151515815260200191505060405180910390a250505b505050509392505050565b73fffffffffffffffffffffffffffffffffffffffe81565b60005481565b6104f961099c565b600060208301905060405180604001604052808451815260200182815250915050919050565b606061052a82610735565b61053357600080fd5b600061053e83610783565b905060608160405190808252806020026020018201604052801561057c57816020015b6105696109b6565b8152602001906001900390816105615790505b509050600061058e85602001516107f4565b8560200151019050600080600090505b848110156105ef576105af8361087d565b91506040518060400160405280838152602001848152508482815181106105d257fe5b60200260200101819052508183019250808060010191505061059e565b5082945050505050919050565b600080826000015111801561061657506021826000015111155b61061f57600080fd5b600061062e83602001516107f4565b9050600081846000015103905060008083866020015101905080519150602083101561066157826020036101000a820491505b81945050505050919050565b6000601582600001511461068057600080fd5b610689826105fc565b9050919050565b606060008260000151116106a357600080fd5b60006106b283602001516107f4565b905060008184600001510390506060816040519080825280601f01601f1916602001820160405280156106f45781602001600182028038833980820191505090505b5090506000816020019050610710848760200151018285610935565b81945050505050919050565b600080823b905060008163ffffffff1611915050919050565b6000808260000151141561074c576000905061077e565b60008083602001519050805160001a915060c060ff168260ff1610156107775760009250505061077e565b6001925050505b919050565b6000808260000151141561079a57600090506107ef565b600080905060006107ae84602001516107f4565b84602001510190506000846000015185602001510190505b808210156107e8576107d78261087d565b8201915082806001019350506107c6565b8293505050505b919050565b600080825160001a9050608060ff16811015610814576000915050610878565b60b860ff16811080610839575060c060ff168110158015610838575060f860ff1681105b5b15610848576001915050610878565b60c060ff168110156108685760018060b80360ff16820301915050610878565b60018060f80360ff168203019150505b919050565b6000806000835160001a9050608060ff1681101561089e576001915061092b565b60b860ff168110156108bb576001608060ff16820301915061092a565b60c060ff168110156108eb5760b78103600185019450806020036101000a85510460018201810193505050610929565b60f860ff1681101561090857600160c060ff168203019150610928565b60f78103600185019450806020036101000a855104600182018101935050505b5b5b5b8192505050919050565b600081141561094357610997565b5b602060ff1681106109735782518252602060ff1683019250602060ff1682019150602060ff1681039050610944565b6000600182602060ff16036101000a03905080198451168184511681811785525050505b505050565b604051806040016040528060008152602001600081525090565b60405180604001604052806000815260200160008152509056fea265627a7a723158208f1ea6fcf63d6911ac5dbfe340be1029614581802c6a750e7d6354b32ce6647c64736f6c63430005110032" + } } }, "burntContract": { - "22640000": "0x70bcA57F4579f58670aB2d18Ef16e02C17553C38" + "22640000": "0x70bcA57F4579f58670aB2d18Ef16e02C17553C38", + "41874000": "0x617b94CCCC2511808A3C9478ebb96f455CF167aA" }, "jaipurBlock": 22770000, "delhiBlock": 29638656, diff --git a/internal/cli/server/chains/test_files/chain_test.json b/internal/cli/server/chains/test_files/chain_test.json index e367547b6a..ba207bf770 100644 --- a/internal/cli/server/chains/test_files/chain_test.json +++ b/internal/cli/server/chains/test_files/chain_test.json @@ -16,6 +16,7 @@ "muirGlacierBlock":2722000, "berlinBlock":13996000, "londonBlock":13996000, + "shanghaiBlock": 41874000, "bor":{ "period":{ "0":2, @@ -44,10 +45,17 @@ "balance":"0x0", "code":"0x60806040526004361061019c5760003560e01c806377d32e94116100ec578063acd06cb31161008a578063e306f77911610064578063e306f77914610a7b578063e614d0d614610aa6578063f2fde38b14610ad1578063fc0c546a14610b225761019c565b8063acd06cb31461097a578063b789543c146109cd578063cc79f97b14610a505761019c565b80639025e64c116100c65780639025e64c146107c957806395d89b4114610859578063a9059cbb146108e9578063abceeba21461094f5761019c565b806377d32e94146106315780638da5cb5b146107435780638f32d59b1461079a5761019c565b806347e7ef24116101595780637019d41a116101335780637019d41a1461053357806370a082311461058a578063715018a6146105ef578063771282f6146106065761019c565b806347e7ef2414610410578063485cc9551461046b57806360f96a8f146104dc5761019c565b806306fdde03146101a15780631499c5921461023157806318160ddd1461028257806319d27d9c146102ad5780632e1a7d4d146103b1578063313ce567146103df575b600080fd5b3480156101ad57600080fd5b506101b6610b79565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101f65780820151818401526020810190506101db565b50505050905090810190601f1680156102235780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561023d57600080fd5b506102806004803603602081101561025457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610bb6565b005b34801561028e57600080fd5b50610297610c24565b6040518082815260200191505060405180910390f35b3480156102b957600080fd5b5061036f600480360360a08110156102d057600080fd5b81019080803590602001906401000000008111156102ed57600080fd5b8201836020820111156102ff57600080fd5b8035906020019184600183028401116401000000008311171561032157600080fd5b9091929391929390803590602001909291908035906020019092919080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610c3a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6103dd600480360360208110156103c757600080fd5b8101908080359060200190929190505050610caa565b005b3480156103eb57600080fd5b506103f4610dfc565b604051808260ff1660ff16815260200191505060405180910390f35b34801561041c57600080fd5b506104696004803603604081101561043357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610e05565b005b34801561047757600080fd5b506104da6004803603604081101561048e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610fc1565b005b3480156104e857600080fd5b506104f1611090565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561053f57600080fd5b506105486110b6565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561059657600080fd5b506105d9600480360360208110156105ad57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506110dc565b6040518082815260200191505060405180910390f35b3480156105fb57600080fd5b506106046110fd565b005b34801561061257600080fd5b5061061b6111cd565b6040518082815260200191505060405180910390f35b34801561063d57600080fd5b506107016004803603604081101561065457600080fd5b81019080803590602001909291908035906020019064010000000081111561067b57600080fd5b82018360208201111561068d57600080fd5b803590602001918460018302840111640100000000831117156106af57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506111d3565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561074f57600080fd5b50610758611358565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156107a657600080fd5b506107af611381565b604051808215151515815260200191505060405180910390f35b3480156107d557600080fd5b506107de6113d8565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561081e578082015181840152602081019050610803565b50505050905090810190601f16801561084b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561086557600080fd5b5061086e611411565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156108ae578082015181840152602081019050610893565b50505050905090810190601f1680156108db5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610935600480360360408110156108ff57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061144e565b604051808215151515815260200191505060405180910390f35b34801561095b57600080fd5b50610964611474565b6040518082815260200191505060405180910390f35b34801561098657600080fd5b506109b36004803603602081101561099d57600080fd5b8101908080359060200190929190505050611501565b604051808215151515815260200191505060405180910390f35b3480156109d957600080fd5b50610a3a600480360360808110156109f057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291908035906020019092919080359060200190929190505050611521565b6040518082815260200191505060405180910390f35b348015610a5c57600080fd5b50610a65611541565b6040518082815260200191505060405180910390f35b348015610a8757600080fd5b50610a90611548565b6040518082815260200191505060405180910390f35b348015610ab257600080fd5b50610abb61154e565b6040518082815260200191505060405180910390f35b348015610add57600080fd5b50610b2060048036036020811015610af457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506115db565b005b348015610b2e57600080fd5b50610b376115f8565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b60606040518060400160405280600b81526020017f4d6174696320546f6b656e000000000000000000000000000000000000000000815250905090565b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260108152602001807f44697361626c656420666561747572650000000000000000000000000000000081525060200191505060405180910390fd5b6000601260ff16600a0a6402540be40002905090565b60006040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260108152602001807f44697361626c656420666561747572650000000000000000000000000000000081525060200191505060405180910390fd5b60003390506000610cba826110dc565b9050610cd18360065461161e90919063ffffffff16565b600681905550600083118015610ce657508234145b610d58576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f496e73756666696369656e7420616d6f756e740000000000000000000000000081525060200191505060405180910390fd5b8173ffffffffffffffffffffffffffffffffffffffff16600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167febff2602b3f468259e1e99f613fed6691f3a6526effe6ef3e768ba7ae7a36c4f8584610dd4876110dc565b60405180848152602001838152602001828152602001935050505060405180910390a3505050565b60006012905090565b610e0d611381565b610e1657600080fd5b600081118015610e535750600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b610ea8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180611da96023913960400191505060405180910390fd5b6000610eb3836110dc565b905060008390508073ffffffffffffffffffffffffffffffffffffffff166108fc849081150290604051600060405180830381858888f19350505050158015610f00573d6000803e3d6000fd5b50610f168360065461163e90919063ffffffff16565b6006819055508373ffffffffffffffffffffffffffffffffffffffff16600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f4e2ca0515ed1aef1395f66b5303bb5d6f1bf9d61a353fa53f73f8ac9973fa9f68585610f98896110dc565b60405180848152602001838152602001828152602001935050505060405180910390a350505050565b600760009054906101000a900460ff1615611027576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180611d866023913960400191505060405180910390fd5b6001600760006101000a81548160ff02191690831515021790555080600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555061108c8261165d565b5050565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008173ffffffffffffffffffffffffffffffffffffffff16319050919050565b611105611381565b61110e57600080fd5b600073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60065481565b60008060008060418551146111ee5760009350505050611352565b602085015192506040850151915060ff6041860151169050601b8160ff16101561121957601b810190505b601b8160ff16141580156112315750601c8160ff1614155b156112425760009350505050611352565b60018682858560405160008152602001604052604051808581526020018460ff1660ff1681526020018381526020018281526020019450505050506020604051602081039080840390855afa15801561129f573d6000803e3d6000fd5b505050602060405103519350600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16141561134e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f4572726f7220696e2065637265636f766572000000000000000000000000000081525060200191505060405180910390fd5b5050505b92915050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614905090565b6040518060400160405280600381526020017f013881000000000000000000000000000000000000000000000000000000000081525081565b60606040518060400160405280600581526020017f4d41544943000000000000000000000000000000000000000000000000000000815250905090565b6000813414611460576000905061146e565b61146b338484611755565b90505b92915050565b6040518060800160405280605b8152602001611e1e605b91396040516020018082805190602001908083835b602083106114c357805182526020820191506020810190506020830392506114a0565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040516020818303038152906040528051906020012081565b60056020528060005260406000206000915054906101000a900460ff1681565b600061153761153286868686611b12565b611be8565b9050949350505050565b6201388181565b60015481565b604051806080016040528060528152602001611dcc605291396040516020018082805190602001908083835b6020831061159d578051825260208201915060208101905060208303925061157a565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040516020818303038152906040528051906020012081565b6115e3611381565b6115ec57600080fd5b6115f58161165d565b50565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008282111561162d57600080fd5b600082840390508091505092915050565b60008082840190508381101561165357600080fd5b8091505092915050565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561169757600080fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000803073ffffffffffffffffffffffffffffffffffffffff166370a08231866040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b1580156117d557600080fd5b505afa1580156117e9573d6000803e3d6000fd5b505050506040513d60208110156117ff57600080fd5b8101908080519060200190929190505050905060003073ffffffffffffffffffffffffffffffffffffffff166370a08231866040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b15801561189157600080fd5b505afa1580156118a5573d6000803e3d6000fd5b505050506040513d60208110156118bb57600080fd5b810190808051906020019092919050505090506118d9868686611c32565b8473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff16600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fe6497e3ee548a3372136af2fcb0696db31fc6cf20260707645068bd3fe97f3c48786863073ffffffffffffffffffffffffffffffffffffffff166370a082318e6040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b1580156119e157600080fd5b505afa1580156119f5573d6000803e3d6000fd5b505050506040513d6020811015611a0b57600080fd5b81019080805190602001909291905050503073ffffffffffffffffffffffffffffffffffffffff166370a082318e6040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015611a9957600080fd5b505afa158015611aad573d6000803e3d6000fd5b505050506040513d6020811015611ac357600080fd5b8101908080519060200190929190505050604051808681526020018581526020018481526020018381526020018281526020019550505050505060405180910390a46001925050509392505050565b6000806040518060800160405280605b8152602001611e1e605b91396040516020018082805190602001908083835b60208310611b645780518252602082019150602081019050602083039250611b41565b6001836020036101000a03801982511681845116808217855250505050505090500191505060405160208183030381529060405280519060200120905060405181815273ffffffffffffffffffffffffffffffffffffffff8716602082015285604082015284606082015283608082015260a0812092505081915050949350505050565b60008060015490506040517f190100000000000000000000000000000000000000000000000000000000000081528160028201528360228201526042812092505081915050919050565b3073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611cd4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f63616e27742073656e6420746f204d524332300000000000000000000000000081525060200191505060405180910390fd5b8173ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f19350505050158015611d1a573d6000803e3d6000fd5b508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a350505056fe54686520636f6e747261637420697320616c726561647920696e697469616c697a6564496e73756666696369656e7420616d6f756e74206f7220696e76616c69642075736572454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c75696e7432353620636861696e49642c6164647265737320766572696679696e67436f6e747261637429546f6b656e5472616e736665724f726465722861646472657373207370656e6465722c75696e7432353620746f6b656e49644f72416d6f756e742c6279746573333220646174612c75696e743235362065787069726174696f6e29a265627a7a72315820ccd6c2a9c259832bbb367986ee06cd87af23022681b0cb22311a864b701d939564736f6c63430005100032" } + }, + "41874000": { + "0x0000000000000000000000000000000000001001": { + "balance": "0x0", + "code": "0x608060405234801561001057600080fd5b506004361061005e576000357c01000000000000000000000000000000000000000000000000000000009004806319494a17146100635780633434735f146100fe5780635407ca6714610148575b600080fd5b6100e46004803603604081101561007957600080fd5b8101908080359060200190929190803590602001906401000000008111156100a057600080fd5b8201836020820111156100b257600080fd5b803590602001918460018302840111640100000000831117156100d457600080fd5b9091929391929390505050610166565b604051808215151515815260200191505060405180910390f35b6101066104d3565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6101506104eb565b6040518082815260200191505060405180910390f35b600073fffffffffffffffffffffffffffffffffffffffe73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461021d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f4e6f742053797374656d2041646465737321000000000000000000000000000081525060200191505060405180910390fd5b606061027461026f85858080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050506104f1565b61051f565b905060006102958260008151811061028857fe5b60200260200101516105fc565b90508060016000540114610311576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f537461746549647320617265206e6f742073657175656e7469616c000000000081525060200191505060405180910390fd5b600080815480929190600101919050555060006103418360018151811061033457fe5b602002602001015161066d565b905060606103628460028151811061035557fe5b6020026020010151610690565b905061036d8261071c565b156104c8576000624c4b409050606084836040516024018083815260200180602001828103825283818151815260200191508051906020019080838360005b838110156103c75780820151818401526020810190506103ac565b50505050905090810190601f1680156103f45780820380516001836020036101000a031916815260200191505b5093505050506040516020818303038152906040527f26c53bea000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050905060008082516020840160008887f19650847f5a22725590b0a51c923940223f7458512164b1113359a735e86e7f27f44791ee88604051808215151515815260200191505060405180910390a250505b505050509392505050565b73fffffffffffffffffffffffffffffffffffffffe81565b60005481565b6104f961099c565b600060208301905060405180604001604052808451815260200182815250915050919050565b606061052a82610735565b61053357600080fd5b600061053e83610783565b905060608160405190808252806020026020018201604052801561057c57816020015b6105696109b6565b8152602001906001900390816105615790505b509050600061058e85602001516107f4565b8560200151019050600080600090505b848110156105ef576105af8361087d565b91506040518060400160405280838152602001848152508482815181106105d257fe5b60200260200101819052508183019250808060010191505061059e565b5082945050505050919050565b600080826000015111801561061657506021826000015111155b61061f57600080fd5b600061062e83602001516107f4565b9050600081846000015103905060008083866020015101905080519150602083101561066157826020036101000a820491505b81945050505050919050565b6000601582600001511461068057600080fd5b610689826105fc565b9050919050565b606060008260000151116106a357600080fd5b60006106b283602001516107f4565b905060008184600001510390506060816040519080825280601f01601f1916602001820160405280156106f45781602001600182028038833980820191505090505b5090506000816020019050610710848760200151018285610935565b81945050505050919050565b600080823b905060008163ffffffff1611915050919050565b6000808260000151141561074c576000905061077e565b60008083602001519050805160001a915060c060ff168260ff1610156107775760009250505061077e565b6001925050505b919050565b6000808260000151141561079a57600090506107ef565b600080905060006107ae84602001516107f4565b84602001510190506000846000015185602001510190505b808210156107e8576107d78261087d565b8201915082806001019350506107c6565b8293505050505b919050565b600080825160001a9050608060ff16811015610814576000915050610878565b60b860ff16811080610839575060c060ff168110158015610838575060f860ff1681105b5b15610848576001915050610878565b60c060ff168110156108685760018060b80360ff16820301915050610878565b60018060f80360ff168203019150505b919050565b6000806000835160001a9050608060ff1681101561089e576001915061092b565b60b860ff168110156108bb576001608060ff16820301915061092a565b60c060ff168110156108eb5760b78103600185019450806020036101000a85510460018201810193505050610929565b60f860ff1681101561090857600160c060ff168203019150610928565b60f78103600185019450806020036101000a855104600182018101935050505b5b5b5b8192505050919050565b600081141561094357610997565b5b602060ff1681106109735782518252602060ff1683019250602060ff1682019150602060ff1681039050610944565b6000600182602060ff16036101000a03905080198451168184511681811785525050505b505050565b604051806040016040528060008152602001600081525090565b60405180604001604052806000815260200160008152509056fea265627a7a723158208f1ea6fcf63d6911ac5dbfe340be1029614581802c6a750e7d6354b32ce6647c64736f6c63430005110032" + } } }, "burntContract":{ - "22640000":"0x70bcA57F4579f58670aB2d18Ef16e02C17553C38" + "22640000":"0x70bcA57F4579f58670aB2d18Ef16e02C17553C38", + "41874000": "0x617b94CCCC2511808A3C9478ebb96f455CF167aA" }, "jaipurBlock":22770000, "delhiBlock": 29638656, diff --git a/internal/cli/server/command_test.go b/internal/cli/server/command_test.go index 9f5468f3d3..de6a2d5efa 100644 --- a/internal/cli/server/command_test.go +++ b/internal/cli/server/command_test.go @@ -41,6 +41,7 @@ func TestFlagsWithoutConfig(t *testing.T) { require.Equal(t, c.config.Identity, "") require.Equal(t, c.config.DataDir, "./data") + require.Equal(t, c.config.KeyStoreDir, "") require.Equal(t, c.config.Verbosity, 3) require.Equal(t, c.config.RPCBatchLimit, uint64(0)) require.Equal(t, c.config.Snapshot, true) @@ -74,6 +75,7 @@ func TestFlagsWithConfig(t *testing.T) { require.Equal(t, c.config.Identity, "") require.Equal(t, c.config.DataDir, "./data") + require.Equal(t, c.config.KeyStoreDir, "./keystore") require.Equal(t, c.config.Verbosity, 3) require.Equal(t, c.config.RPCBatchLimit, uint64(0)) require.Equal(t, c.config.Snapshot, true) @@ -105,6 +107,7 @@ func TestFlagsWithConfigAndFlags(t *testing.T) { "--config", "./testdata/test.toml", "--identity", "Anon", "--datadir", "", + "--keystore", "", "--verbosity", "0", "--rpc.batchlimit", "5", "--snapshot=false", @@ -128,6 +131,7 @@ func TestFlagsWithConfigAndFlags(t *testing.T) { require.Equal(t, c.config.Identity, "Anon") require.Equal(t, c.config.DataDir, "") + require.Equal(t, c.config.KeyStoreDir, "") require.Equal(t, c.config.Verbosity, 0) require.Equal(t, c.config.RPCBatchLimit, uint64(5)) require.Equal(t, c.config.Snapshot, false) diff --git a/internal/cli/server/config.go b/internal/cli/server/config.go index 302d310374..cb682e0c40 100644 --- a/internal/cli/server/config.go +++ b/internal/cli/server/config.go @@ -605,6 +605,7 @@ func DefaultConfig() *Config { DataDir: DefaultDataDir(), Ancient: "", DBEngine: "leveldb", + KeyStoreDir: "", Logging: &LoggingConfig{ Vmodule: "", Json: false, diff --git a/internal/cli/server/config_legacy_test.go b/internal/cli/server/config_legacy_test.go index e0b1a76577..aa6cffc470 100644 --- a/internal/cli/server/config_legacy_test.go +++ b/internal/cli/server/config_legacy_test.go @@ -17,6 +17,7 @@ func TestConfigLegacy(t *testing.T) { testConfig.Identity = "" testConfig.DataDir = "./data" + testConfig.KeyStoreDir = "./keystore" testConfig.Verbosity = 3 testConfig.RPCBatchLimit = 0 testConfig.Snapshot = true diff --git a/internal/cli/server/flags.go b/internal/cli/server/flags.go index 12995977ff..35150d5a48 100644 --- a/internal/cli/server/flags.go +++ b/internal/cli/server/flags.go @@ -64,9 +64,10 @@ func (c *Command) Flags(config *Config) *flagset.Flagset { Default: c.cliConfig.DBEngine, }) f.StringFlag(&flagset.StringFlag{ - Name: "keystore", - Usage: "Path of the directory where keystores are located", - Value: &c.cliConfig.KeyStoreDir, + Name: "keystore", + Usage: "Path of the directory where keystores are located", + Value: &c.cliConfig.KeyStoreDir, + Default: c.cliConfig.KeyStoreDir, }) f.Uint64Flag(&flagset.Uint64Flag{ Name: "rpc.batchlimit", diff --git a/internal/cli/server/testdata/test.toml b/internal/cli/server/testdata/test.toml index 522322b2a3..04b2dbed35 100644 --- a/internal/cli/server/testdata/test.toml +++ b/internal/cli/server/testdata/test.toml @@ -1,5 +1,6 @@ identity = "" datadir = "./data" +keystore = "./keystore" verbosity = 3 "rpc.batchlimit" = 0 snapshot = true diff --git a/internal/ethapi/bor_api.go b/internal/ethapi/bor_api.go index 0159f12b4d..8129989b58 100644 --- a/internal/ethapi/bor_api.go +++ b/internal/ethapi/bor_api.go @@ -74,7 +74,11 @@ func (api *BorAPI) SendRawTransactionConditional(ctx context.Context, input hexu } currentHeader := api.b.CurrentHeader() - currentState, _, _ := api.b.StateAndHeaderByNumber(ctx, rpc.BlockNumber(currentHeader.Number.Int64())) + currentState, _, err := api.b.StateAndHeaderByNumber(ctx, rpc.BlockNumber(currentHeader.Number.Int64())) + + if currentState == nil || err != nil { + return common.Hash{}, err + } // check block number range if err := currentHeader.ValidateBlockNumberOptions4337(options.BlockNumberMin, options.BlockNumberMax); err != nil { diff --git a/light/txpool.go b/light/txpool.go index b83b244757..b866981ebd 100644 --- a/light/txpool.go +++ b/light/txpool.go @@ -341,7 +341,7 @@ func (pool *TxPool) setNewHead(head *types.Header) { next := new(big.Int).Add(head.Number, big.NewInt(1)) pool.istanbul = pool.config.IsIstanbul(next) pool.eip2718 = pool.config.IsBerlin(next) - pool.shanghai = pool.config.IsShanghai(uint64(time.Now().Unix())) + pool.shanghai = pool.config.IsShanghai(next) } // Stop stops the light transaction pool diff --git a/miner/stress/beacon/main.go b/miner/stress/beacon/main.go index a94e6e9467..abdc7b71f5 100644 --- a/miner/stress/beacon/main.go +++ b/miner/stress/beacon/main.go @@ -1,619 +1,619 @@ -// Copyright 2021 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see . - -// This file contains a miner stress test for the eth1/2 transition +// // Copyright 2021 The go-ethereum Authors +// // This file is part of the go-ethereum library. +// // +// // The go-ethereum library is free software: you can redistribute it and/or modify +// // it under the terms of the GNU Lesser General Public License as published by +// // the Free Software Foundation, either version 3 of the License, or +// // (at your option) any later version. +// // +// // The go-ethereum library is distributed in the hope that it will be useful, +// // but WITHOUT ANY WARRANTY; without even the implied warranty of +// // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// // GNU Lesser General Public License for more details. +// // +// // You should have received a copy of the GNU Lesser General Public License +// // along with the go-ethereum library. If not, see . + +// // This file contains a miner stress test for the eth1/2 transition package main -import ( - "crypto/ecdsa" - "errors" - "math/big" - "math/rand" - "os" - "path/filepath" - "time" - - "github.com/ethereum/go-ethereum/accounts/keystore" - "github.com/ethereum/go-ethereum/beacon/engine" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/fdlimit" - "github.com/ethereum/go-ethereum/consensus/ethash" - "github.com/ethereum/go-ethereum/core" - "github.com/ethereum/go-ethereum/core/txpool" - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/eth" - ethcatalyst "github.com/ethereum/go-ethereum/eth/catalyst" - "github.com/ethereum/go-ethereum/eth/downloader" - "github.com/ethereum/go-ethereum/eth/ethconfig" - "github.com/ethereum/go-ethereum/les" - lescatalyst "github.com/ethereum/go-ethereum/les/catalyst" - "github.com/ethereum/go-ethereum/log" - "github.com/ethereum/go-ethereum/miner" - "github.com/ethereum/go-ethereum/node" - "github.com/ethereum/go-ethereum/p2p" - "github.com/ethereum/go-ethereum/p2p/enode" - "github.com/ethereum/go-ethereum/params" -) - -type nodetype int - -const ( - legacyMiningNode nodetype = iota - legacyNormalNode - eth2MiningNode - eth2NormalNode - eth2LightClient -) - -func (typ nodetype) String() string { - switch typ { - case legacyMiningNode: - return "legacyMiningNode" - case legacyNormalNode: - return "legacyNormalNode" - case eth2MiningNode: - return "eth2MiningNode" - case eth2NormalNode: - return "eth2NormalNode" - case eth2LightClient: - return "eth2LightClient" - default: - return "undefined" - } -} - -var ( - // transitionDifficulty is the target total difficulty for transition - transitionDifficulty = new(big.Int).Mul(big.NewInt(20), params.MinimumDifficulty) - - // blockInterval is the time interval for creating a new eth2 block - blockIntervalInt = 3 - blockInterval = time.Second * time.Duration(blockIntervalInt) - - // finalizationDist is the block distance for finalizing block - finalizationDist = 10 -) - -type ethNode struct { - typ nodetype - stack *node.Node - enode *enode.Node - api *ethcatalyst.ConsensusAPI - ethBackend *eth.Ethereum - lapi *lescatalyst.ConsensusAPI - lesBackend *les.LightEthereum -} - -func newNode(typ nodetype, genesis *core.Genesis, enodes []*enode.Node) *ethNode { - var ( - err error - api *ethcatalyst.ConsensusAPI - lapi *lescatalyst.ConsensusAPI - stack *node.Node - ethBackend *eth.Ethereum - lesBackend *les.LightEthereum - ) - // Start the node and wait until it's up - if typ == eth2LightClient { - stack, lesBackend, lapi, err = makeLightNode(genesis) - } else { - stack, ethBackend, api, err = makeFullNode(genesis) - } - - if err != nil { - panic(err) - } - - for stack.Server().NodeInfo().Ports.Listener == 0 { - time.Sleep(250 * time.Millisecond) - } - // Connect the node to all the previous ones - for _, n := range enodes { - stack.Server().AddPeer(n) - } - - enode := stack.Server().Self() - - // Inject the signer key and start sealing with it - stack.AccountManager().AddBackend(keystore.NewPlaintextKeyStore("beacon-stress")) - ks := stack.AccountManager().Backends(keystore.KeyStoreType) - - if len(ks) == 0 { - panic("Keystore is not available") - } - - store := ks[0].(*keystore.KeyStore) - if _, err := store.NewAccount(""); err != nil { - panic(err) - } - - return ðNode{ - typ: typ, - api: api, - ethBackend: ethBackend, - lapi: lapi, - lesBackend: lesBackend, - stack: stack, - enode: enode, - } -} - -func (n *ethNode) assembleBlock(parentHash common.Hash, parentTimestamp uint64) (*engine.ExecutableData, error) { - if n.typ != eth2MiningNode { - return nil, errors.New("invalid node type") - } - - timestamp := uint64(time.Now().Unix()) - if timestamp <= parentTimestamp { - timestamp = parentTimestamp + 1 - } - - payloadAttribute := engine.PayloadAttributes{ - Timestamp: timestamp, - Random: common.Hash{}, - SuggestedFeeRecipient: common.HexToAddress("0xdeadbeef"), - } - fcState := engine.ForkchoiceStateV1{ - HeadBlockHash: parentHash, - SafeBlockHash: common.Hash{}, - FinalizedBlockHash: common.Hash{}, - } - - payload, err := n.api.ForkchoiceUpdatedV1(fcState, &payloadAttribute) - if err != nil { - return nil, err - } - - time.Sleep(time.Second * 5) // give enough time for block creation - - return n.api.GetPayloadV1(*payload.PayloadID) -} - -func (n *ethNode) insertBlock(eb engine.ExecutableData) error { - if !eth2types(n.typ) { - return errors.New("invalid node type") - } - - switch n.typ { - case eth2NormalNode, eth2MiningNode: - newResp, err := n.api.NewPayloadV1(eb) - if err != nil { - return err - } else if newResp.Status != "VALID" { - return errors.New("failed to insert block") - } - - return nil - case eth2LightClient: - newResp, err := n.lapi.ExecutePayloadV1(eb) - if err != nil { - return err - } else if newResp.Status != "VALID" { - return errors.New("failed to insert block") - } - - return nil - default: - return errors.New("undefined node") - } -} - -func (n *ethNode) insertBlockAndSetHead(_ *types.Header, ed engine.ExecutableData) error { - if !eth2types(n.typ) { - return errors.New("invalid node type") - } - - if err := n.insertBlock(ed); err != nil { - return err - } - - block, err := engine.ExecutableDataToBlock(ed) - if err != nil { - return err - } - - fcState := engine.ForkchoiceStateV1{ - HeadBlockHash: block.ParentHash(), - SafeBlockHash: common.Hash{}, - FinalizedBlockHash: common.Hash{}, - } - - switch n.typ { - case eth2NormalNode, eth2MiningNode: - if _, err := n.api.ForkchoiceUpdatedV1(fcState, nil); err != nil { - return err - } - - return nil - case eth2LightClient: - if _, err := n.lapi.ForkchoiceUpdatedV1(fcState, nil); err != nil { - return err - } - - return nil - default: - return errors.New("undefined node") - } -} - -type nodeManager struct { - genesis *core.Genesis - genesisBlock *types.Block - nodes []*ethNode - enodes []*enode.Node - close chan struct{} -} - -func newNodeManager(genesis *core.Genesis) *nodeManager { - return &nodeManager{ - close: make(chan struct{}), - genesis: genesis, - genesisBlock: genesis.ToBlock(), - } -} - -func (mgr *nodeManager) createNode(typ nodetype) { - node := newNode(typ, mgr.genesis, mgr.enodes) - mgr.nodes = append(mgr.nodes, node) - mgr.enodes = append(mgr.enodes, node.enode) -} - -func (mgr *nodeManager) getNodes(typ nodetype) []*ethNode { - var ret []*ethNode - - for _, node := range mgr.nodes { - if node.typ == typ { - ret = append(ret, node) - } - } - - return ret -} - -func (mgr *nodeManager) startMining() { - for _, node := range append(mgr.getNodes(eth2MiningNode), mgr.getNodes(legacyMiningNode)...) { - if err := node.ethBackend.StartMining(1); err != nil { - panic(err) - } - } -} - -func (mgr *nodeManager) shutdown() { - close(mgr.close) - - for _, node := range mgr.nodes { - node.stack.Close() - } -} - -func (mgr *nodeManager) run() { - if len(mgr.nodes) == 0 { - return - } - - chain := mgr.nodes[0].ethBackend.BlockChain() - sink := make(chan core.ChainHeadEvent, 1024) - - sub := chain.SubscribeChainHeadEvent(sink) - defer sub.Unsubscribe() - - var ( - transitioned bool - parentBlock *types.Block - waitFinalise []*types.Block - ) - - timer := time.NewTimer(0) - defer timer.Stop() - <-timer.C // discard the initial tick - - // Handle the by default transition. - if transitionDifficulty.Sign() == 0 { - transitioned = true - parentBlock = mgr.genesisBlock - - timer.Reset(blockInterval) - log.Info("Enable the transition by default") - } - - // Handle the block finalization. - checkFinalise := func() { - if parentBlock == nil { - return - } - - if len(waitFinalise) == 0 { - return - } - - oldest := waitFinalise[0] - if oldest.NumberU64() > parentBlock.NumberU64() { - return - } - - distance := parentBlock.NumberU64() - oldest.NumberU64() - if int(distance) < finalizationDist { - return - } - - nodes := mgr.getNodes(eth2MiningNode) - nodes = append(nodes, mgr.getNodes(eth2NormalNode)...) - //nodes = append(nodes, mgr.getNodes(eth2LightClient)...) - for _, node := range nodes { - fcState := engine.ForkchoiceStateV1{ - HeadBlockHash: parentBlock.Hash(), - SafeBlockHash: oldest.Hash(), - FinalizedBlockHash: oldest.Hash(), - } - _, _ = node.api.ForkchoiceUpdatedV1(fcState, nil) - } - - log.Info("Finalised eth2 block", "number", oldest.NumberU64(), "hash", oldest.Hash()) - - waitFinalise = waitFinalise[1:] - } - - for { - checkFinalise() - select { - case <-mgr.close: - return - - case ev := <-sink: - if transitioned { - continue - } - - td := chain.GetTd(ev.Block.Hash(), ev.Block.NumberU64()) - if td.Cmp(transitionDifficulty) < 0 { - continue - } - - transitioned, parentBlock = true, ev.Block - - timer.Reset(blockInterval) - log.Info("Transition difficulty reached", "td", td, "target", transitionDifficulty, "number", ev.Block.NumberU64(), "hash", ev.Block.Hash()) - - case <-timer.C: - producers := mgr.getNodes(eth2MiningNode) - if len(producers) == 0 { - continue - } - - hash, timestamp := parentBlock.Hash(), parentBlock.Time() - if parentBlock.NumberU64() == 0 { - timestamp = uint64(time.Now().Unix()) - uint64(blockIntervalInt) - } - - ed, err := producers[0].assembleBlock(hash, timestamp) - if err != nil { - log.Error("Failed to assemble the block", "err", err) - continue - } - - block, _ := engine.ExecutableDataToBlock(*ed) - - nodes := mgr.getNodes(eth2MiningNode) - nodes = append(nodes, mgr.getNodes(eth2NormalNode)...) - nodes = append(nodes, mgr.getNodes(eth2LightClient)...) - - for _, node := range nodes { - if err := node.insertBlockAndSetHead(parentBlock.Header(), *ed); err != nil { - log.Error("Failed to insert block", "type", node.typ, "err", err) - } - } - - log.Info("Create and insert eth2 block", "number", ed.Number) - - parentBlock = block - waitFinalise = append(waitFinalise, block) - - timer.Reset(blockInterval) - } - } -} - -func main() { - log.Root().SetHandler(log.LvlFilterHandler(log.LvlInfo, log.StreamHandler(os.Stderr, log.TerminalFormat(true)))) - fdlimit.Raise(2048) - - // Generate a batch of accounts to seal and fund with - faucets := make([]*ecdsa.PrivateKey, 16) - for i := 0; i < len(faucets); i++ { - faucets[i], _ = crypto.GenerateKey() - } - // Pre-generate the ethash mining DAG so we don't race - ethash.MakeDataset(1, filepath.Join(os.Getenv("HOME"), ".ethash")) - - // Create an Ethash network - genesis := makeGenesis(faucets) - - manager := newNodeManager(genesis) - defer manager.shutdown() - - manager.createNode(eth2NormalNode) - manager.createNode(eth2MiningNode) - manager.createNode(legacyMiningNode) - manager.createNode(legacyNormalNode) - manager.createNode(eth2LightClient) - - // Iterate over all the nodes and start mining - time.Sleep(3 * time.Second) - - if transitionDifficulty.Sign() != 0 { - manager.startMining() - } - - go manager.run() - - // Start injecting transactions from the faucets like crazy - time.Sleep(3 * time.Second) - - nonces := make([]uint64, len(faucets)) - - for { - // Pick a random mining node - nodes := manager.getNodes(eth2MiningNode) - - index := rand.Intn(len(faucets)) - node := nodes[index%len(nodes)] - - // Create a self transaction and inject into the pool - // nolint:gosec - tx, err := types.SignTx(types.NewTransaction(nonces[index], crypto.PubkeyToAddress(faucets[index].PublicKey), new(big.Int), 21000, big.NewInt(10_000_000_000+rand.Int63n(6_553_600_000)), nil), types.HomesteadSigner{}, faucets[index]) - if err != nil { - panic(err) - } - - if err := node.ethBackend.TxPool().AddLocal(tx); err != nil { - panic(err) - } - - nonces[index]++ - - // Wait if we're too saturated - if pend, _ := node.ethBackend.TxPool().Stats(); pend > 2048 { - time.Sleep(100 * time.Millisecond) - } - } -} - -// makeGenesis creates a custom Ethash genesis block based on some pre-defined -// faucet accounts. -func makeGenesis(faucets []*ecdsa.PrivateKey) *core.Genesis { - genesis := core.DefaultGenesisBlock() - genesis.Difficulty = params.MinimumDifficulty - genesis.GasLimit = 25000000 - - genesis.BaseFee = big.NewInt(params.InitialBaseFee) - genesis.Config = params.AllEthashProtocolChanges - genesis.Config.TerminalTotalDifficulty = transitionDifficulty - - genesis.Alloc = core.GenesisAlloc{} - for _, faucet := range faucets { - genesis.Alloc[crypto.PubkeyToAddress(faucet.PublicKey)] = core.GenesisAccount{ - Balance: new(big.Int).Exp(big.NewInt(2), big.NewInt(128), nil), - } - } - - return genesis -} - -func makeFullNode(genesis *core.Genesis) (*node.Node, *eth.Ethereum, *ethcatalyst.ConsensusAPI, error) { - // Define the basic configurations for the Ethereum node - datadir, _ := os.MkdirTemp("", "") - - config := &node.Config{ - Name: "geth", - Version: params.Version, - DataDir: datadir, - P2P: p2p.Config{ - ListenAddr: "0.0.0.0:0", - NoDiscovery: true, - MaxPeers: 25, - }, - UseLightweightKDF: true, - } - // Create the node and configure a full Ethereum node on it - stack, err := node.New(config) - if err != nil { - return nil, nil, nil, err - } - - econfig := ðconfig.Config{ - Genesis: genesis, - NetworkId: genesis.Config.ChainID.Uint64(), - SyncMode: downloader.FullSync, - DatabaseCache: 256, - DatabaseHandles: 256, - TxPool: txpool.DefaultConfig, - GPO: ethconfig.Defaults.GPO, - Ethash: ethconfig.Defaults.Ethash, - Miner: miner.Config{ - GasFloor: genesis.GasLimit * 9 / 10, - GasCeil: genesis.GasLimit * 11 / 10, - GasPrice: big.NewInt(1), - Recommit: 1 * time.Second, - }, - LightServ: 100, - LightPeers: 10, - LightNoSyncServe: true, - } - - ethBackend, err := eth.New(stack, econfig) - if err != nil { - return nil, nil, nil, err - } - - _, err = les.NewLesServer(stack, ethBackend, econfig) - if err != nil { - log.Crit("Failed to create the LES server", "err", err) - } - - err = stack.Start() - - return stack, ethBackend, ethcatalyst.NewConsensusAPI(ethBackend), err -} - -func makeLightNode(genesis *core.Genesis) (*node.Node, *les.LightEthereum, *lescatalyst.ConsensusAPI, error) { - // Define the basic configurations for the Ethereum node - datadir, _ := os.MkdirTemp("", "") - - config := &node.Config{ - Name: "geth", - Version: params.Version, - DataDir: datadir, - P2P: p2p.Config{ - ListenAddr: "0.0.0.0:0", - NoDiscovery: true, - MaxPeers: 25, - }, - UseLightweightKDF: true, - } - // Create the node and configure a full Ethereum node on it - stack, err := node.New(config) - if err != nil { - return nil, nil, nil, err - } - - lesBackend, err := les.New(stack, ðconfig.Config{ - Genesis: genesis, - NetworkId: genesis.Config.ChainID.Uint64(), - SyncMode: downloader.LightSync, - DatabaseCache: 256, - DatabaseHandles: 256, - TxPool: txpool.DefaultConfig, - GPO: ethconfig.Defaults.GPO, - Ethash: ethconfig.Defaults.Ethash, - LightPeers: 10, - }) - if err != nil { - return nil, nil, nil, err - } - - err = stack.Start() - - return stack, lesBackend, lescatalyst.NewConsensusAPI(lesBackend), err -} - -func eth2types(typ nodetype) bool { - if typ == eth2LightClient || typ == eth2NormalNode || typ == eth2MiningNode { - return true - } - - return false -} +// import ( +// "crypto/ecdsa" +// "errors" +// "math/big" +// "math/rand" +// "os" +// "path/filepath" +// "time" + +// "github.com/ethereum/go-ethereum/accounts/keystore" +// "github.com/ethereum/go-ethereum/beacon/engine" +// "github.com/ethereum/go-ethereum/common" +// "github.com/ethereum/go-ethereum/common/fdlimit" +// "github.com/ethereum/go-ethereum/consensus/ethash" +// "github.com/ethereum/go-ethereum/core" +// "github.com/ethereum/go-ethereum/core/txpool" +// "github.com/ethereum/go-ethereum/core/types" +// "github.com/ethereum/go-ethereum/crypto" +// "github.com/ethereum/go-ethereum/eth" +// ethcatalyst "github.com/ethereum/go-ethereum/eth/catalyst" +// "github.com/ethereum/go-ethereum/eth/downloader" +// "github.com/ethereum/go-ethereum/eth/ethconfig" +// "github.com/ethereum/go-ethereum/les" +// lescatalyst "github.com/ethereum/go-ethereum/les/catalyst" +// "github.com/ethereum/go-ethereum/log" +// "github.com/ethereum/go-ethereum/miner" +// "github.com/ethereum/go-ethereum/node" +// "github.com/ethereum/go-ethereum/p2p" +// "github.com/ethereum/go-ethereum/p2p/enode" +// "github.com/ethereum/go-ethereum/params" +// ) + +// type nodetype int + +// const ( +// legacyMiningNode nodetype = iota +// legacyNormalNode +// eth2MiningNode +// eth2NormalNode +// eth2LightClient +// ) + +// func (typ nodetype) String() string { +// switch typ { +// case legacyMiningNode: +// return "legacyMiningNode" +// case legacyNormalNode: +// return "legacyNormalNode" +// case eth2MiningNode: +// return "eth2MiningNode" +// case eth2NormalNode: +// return "eth2NormalNode" +// case eth2LightClient: +// return "eth2LightClient" +// default: +// return "undefined" +// } +// } + +// var ( +// // transitionDifficulty is the target total difficulty for transition +// transitionDifficulty = new(big.Int).Mul(big.NewInt(20), params.MinimumDifficulty) + +// // blockInterval is the time interval for creating a new eth2 block +// blockIntervalInt = 3 +// blockInterval = time.Second * time.Duration(blockIntervalInt) + +// // finalizationDist is the block distance for finalizing block +// finalizationDist = 10 +// ) + +// type ethNode struct { +// typ nodetype +// stack *node.Node +// enode *enode.Node +// api *ethcatalyst.ConsensusAPI +// ethBackend *eth.Ethereum +// lapi *lescatalyst.ConsensusAPI +// lesBackend *les.LightEthereum +// } + +// func newNode(typ nodetype, genesis *core.Genesis, enodes []*enode.Node) *ethNode { +// var ( +// err error +// api *ethcatalyst.ConsensusAPI +// lapi *lescatalyst.ConsensusAPI +// stack *node.Node +// ethBackend *eth.Ethereum +// lesBackend *les.LightEthereum +// ) +// // Start the node and wait until it's up +// if typ == eth2LightClient { +// stack, lesBackend, lapi, err = makeLightNode(genesis) +// } else { +// stack, ethBackend, api, err = makeFullNode(genesis) +// } + +// if err != nil { +// panic(err) +// } + +// for stack.Server().NodeInfo().Ports.Listener == 0 { +// time.Sleep(250 * time.Millisecond) +// } +// // Connect the node to all the previous ones +// for _, n := range enodes { +// stack.Server().AddPeer(n) +// } + +// enode := stack.Server().Self() + +// // Inject the signer key and start sealing with it +// stack.AccountManager().AddBackend(keystore.NewPlaintextKeyStore("beacon-stress")) +// ks := stack.AccountManager().Backends(keystore.KeyStoreType) + +// if len(ks) == 0 { +// panic("Keystore is not available") +// } + +// store := ks[0].(*keystore.KeyStore) +// if _, err := store.NewAccount(""); err != nil { +// panic(err) +// } + +// return ðNode{ +// typ: typ, +// api: api, +// ethBackend: ethBackend, +// lapi: lapi, +// lesBackend: lesBackend, +// stack: stack, +// enode: enode, +// } +// } + +// func (n *ethNode) assembleBlock(parentHash common.Hash, parentTimestamp uint64) (*engine.ExecutableData, error) { +// if n.typ != eth2MiningNode { +// return nil, errors.New("invalid node type") +// } + +// timestamp := uint64(time.Now().Unix()) +// if timestamp <= parentTimestamp { +// timestamp = parentTimestamp + 1 +// } + +// payloadAttribute := engine.PayloadAttributes{ +// Timestamp: timestamp, +// Random: common.Hash{}, +// SuggestedFeeRecipient: common.HexToAddress("0xdeadbeef"), +// } +// fcState := engine.ForkchoiceStateV1{ +// HeadBlockHash: parentHash, +// SafeBlockHash: common.Hash{}, +// FinalizedBlockHash: common.Hash{}, +// } + +// payload, err := n.api.ForkchoiceUpdatedV1(fcState, &payloadAttribute) +// if err != nil { +// return nil, err +// } + +// time.Sleep(time.Second * 5) // give enough time for block creation + +// return n.api.GetPayloadV1(*payload.PayloadID) +// } + +// func (n *ethNode) insertBlock(eb engine.ExecutableData) error { +// if !eth2types(n.typ) { +// return errors.New("invalid node type") +// } + +// switch n.typ { +// case eth2NormalNode, eth2MiningNode: +// newResp, err := n.api.NewPayloadV1(eb) +// if err != nil { +// return err +// } else if newResp.Status != "VALID" { +// return errors.New("failed to insert block") +// } + +// return nil +// case eth2LightClient: +// newResp, err := n.lapi.ExecutePayloadV1(eb) +// if err != nil { +// return err +// } else if newResp.Status != "VALID" { +// return errors.New("failed to insert block") +// } + +// return nil +// default: +// return errors.New("undefined node") +// } +// } + +// func (n *ethNode) insertBlockAndSetHead(_ *types.Header, ed engine.ExecutableData) error { +// if !eth2types(n.typ) { +// return errors.New("invalid node type") +// } + +// if err := n.insertBlock(ed); err != nil { +// return err +// } + +// block, err := engine.ExecutableDataToBlock(ed) +// if err != nil { +// return err +// } + +// fcState := engine.ForkchoiceStateV1{ +// HeadBlockHash: block.ParentHash(), +// SafeBlockHash: common.Hash{}, +// FinalizedBlockHash: common.Hash{}, +// } + +// switch n.typ { +// case eth2NormalNode, eth2MiningNode: +// if _, err := n.api.ForkchoiceUpdatedV1(fcState, nil); err != nil { +// return err +// } + +// return nil +// case eth2LightClient: +// if _, err := n.lapi.ForkchoiceUpdatedV1(fcState, nil); err != nil { +// return err +// } + +// return nil +// default: +// return errors.New("undefined node") +// } +// } + +// type nodeManager struct { +// genesis *core.Genesis +// genesisBlock *types.Block +// nodes []*ethNode +// enodes []*enode.Node +// close chan struct{} +// } + +// func newNodeManager(genesis *core.Genesis) *nodeManager { +// return &nodeManager{ +// close: make(chan struct{}), +// genesis: genesis, +// genesisBlock: genesis.ToBlock(), +// } +// } + +// func (mgr *nodeManager) createNode(typ nodetype) { +// node := newNode(typ, mgr.genesis, mgr.enodes) +// mgr.nodes = append(mgr.nodes, node) +// mgr.enodes = append(mgr.enodes, node.enode) +// } + +// func (mgr *nodeManager) getNodes(typ nodetype) []*ethNode { +// var ret []*ethNode + +// for _, node := range mgr.nodes { +// if node.typ == typ { +// ret = append(ret, node) +// } +// } + +// return ret +// } + +// func (mgr *nodeManager) startMining() { +// for _, node := range append(mgr.getNodes(eth2MiningNode), mgr.getNodes(legacyMiningNode)...) { +// if err := node.ethBackend.StartMining(1); err != nil { +// panic(err) +// } +// } +// } + +// func (mgr *nodeManager) shutdown() { +// close(mgr.close) + +// for _, node := range mgr.nodes { +// node.stack.Close() +// } +// } + +// func (mgr *nodeManager) run() { +// if len(mgr.nodes) == 0 { +// return +// } + +// chain := mgr.nodes[0].ethBackend.BlockChain() +// sink := make(chan core.ChainHeadEvent, 1024) + +// sub := chain.SubscribeChainHeadEvent(sink) +// defer sub.Unsubscribe() + +// var ( +// transitioned bool +// parentBlock *types.Block +// waitFinalise []*types.Block +// ) + +// timer := time.NewTimer(0) +// defer timer.Stop() +// <-timer.C // discard the initial tick + +// // Handle the by default transition. +// if transitionDifficulty.Sign() == 0 { +// transitioned = true +// parentBlock = mgr.genesisBlock + +// timer.Reset(blockInterval) +// log.Info("Enable the transition by default") +// } + +// // Handle the block finalization. +// checkFinalise := func() { +// if parentBlock == nil { +// return +// } + +// if len(waitFinalise) == 0 { +// return +// } + +// oldest := waitFinalise[0] +// if oldest.NumberU64() > parentBlock.NumberU64() { +// return +// } + +// distance := parentBlock.NumberU64() - oldest.NumberU64() +// if int(distance) < finalizationDist { +// return +// } + +// nodes := mgr.getNodes(eth2MiningNode) +// nodes = append(nodes, mgr.getNodes(eth2NormalNode)...) +// //nodes = append(nodes, mgr.getNodes(eth2LightClient)...) +// for _, node := range nodes { +// fcState := engine.ForkchoiceStateV1{ +// HeadBlockHash: parentBlock.Hash(), +// SafeBlockHash: oldest.Hash(), +// FinalizedBlockHash: oldest.Hash(), +// } +// _, _ = node.api.ForkchoiceUpdatedV1(fcState, nil) +// } + +// log.Info("Finalised eth2 block", "number", oldest.NumberU64(), "hash", oldest.Hash()) + +// waitFinalise = waitFinalise[1:] +// } + +// for { +// checkFinalise() +// select { +// case <-mgr.close: +// return + +// case ev := <-sink: +// if transitioned { +// continue +// } + +// td := chain.GetTd(ev.Block.Hash(), ev.Block.NumberU64()) +// if td.Cmp(transitionDifficulty) < 0 { +// continue +// } + +// transitioned, parentBlock = true, ev.Block + +// timer.Reset(blockInterval) +// log.Info("Transition difficulty reached", "td", td, "target", transitionDifficulty, "number", ev.Block.NumberU64(), "hash", ev.Block.Hash()) + +// case <-timer.C: +// producers := mgr.getNodes(eth2MiningNode) +// if len(producers) == 0 { +// continue +// } + +// hash, timestamp := parentBlock.Hash(), parentBlock.Time() +// if parentBlock.NumberU64() == 0 { +// timestamp = uint64(time.Now().Unix()) - uint64(blockIntervalInt) +// } + +// ed, err := producers[0].assembleBlock(hash, timestamp) +// if err != nil { +// log.Error("Failed to assemble the block", "err", err) +// continue +// } + +// block, _ := engine.ExecutableDataToBlock(*ed) + +// nodes := mgr.getNodes(eth2MiningNode) +// nodes = append(nodes, mgr.getNodes(eth2NormalNode)...) +// nodes = append(nodes, mgr.getNodes(eth2LightClient)...) + +// for _, node := range nodes { +// if err := node.insertBlockAndSetHead(parentBlock.Header(), *ed); err != nil { +// log.Error("Failed to insert block", "type", node.typ, "err", err) +// } +// } + +// log.Info("Create and insert eth2 block", "number", ed.Number) + +// parentBlock = block +// waitFinalise = append(waitFinalise, block) + +// timer.Reset(blockInterval) +// } +// } +// } + +// func main() { +// log.Root().SetHandler(log.LvlFilterHandler(log.LvlInfo, log.StreamHandler(os.Stderr, log.TerminalFormat(true)))) +// fdlimit.Raise(2048) + +// // Generate a batch of accounts to seal and fund with +// faucets := make([]*ecdsa.PrivateKey, 16) +// for i := 0; i < len(faucets); i++ { +// faucets[i], _ = crypto.GenerateKey() +// } +// // Pre-generate the ethash mining DAG so we don't race +// ethash.MakeDataset(1, filepath.Join(os.Getenv("HOME"), ".ethash")) + +// // Create an Ethash network +// genesis := makeGenesis(faucets) + +// manager := newNodeManager(genesis) +// defer manager.shutdown() + +// manager.createNode(eth2NormalNode) +// manager.createNode(eth2MiningNode) +// manager.createNode(legacyMiningNode) +// manager.createNode(legacyNormalNode) +// manager.createNode(eth2LightClient) + +// // Iterate over all the nodes and start mining +// time.Sleep(3 * time.Second) + +// if transitionDifficulty.Sign() != 0 { +// manager.startMining() +// } + +// go manager.run() + +// // Start injecting transactions from the faucets like crazy +// time.Sleep(3 * time.Second) + +// nonces := make([]uint64, len(faucets)) + +// for { +// // Pick a random mining node +// nodes := manager.getNodes(eth2MiningNode) + +// index := rand.Intn(len(faucets)) +// node := nodes[index%len(nodes)] + +// // Create a self transaction and inject into the pool +// // nolint:gosec +// tx, err := types.SignTx(types.NewTransaction(nonces[index], crypto.PubkeyToAddress(faucets[index].PublicKey), new(big.Int), 21000, big.NewInt(10_000_000_000+rand.Int63n(6_553_600_000)), nil), types.HomesteadSigner{}, faucets[index]) +// if err != nil { +// panic(err) +// } + +// if err := node.ethBackend.TxPool().AddLocal(tx); err != nil { +// panic(err) +// } + +// nonces[index]++ + +// // Wait if we're too saturated +// if pend, _ := node.ethBackend.TxPool().Stats(); pend > 2048 { +// time.Sleep(100 * time.Millisecond) +// } +// } +// } + +// // makeGenesis creates a custom Ethash genesis block based on some pre-defined +// // faucet accounts. +// func makeGenesis(faucets []*ecdsa.PrivateKey) *core.Genesis { +// genesis := core.DefaultGenesisBlock() +// genesis.Difficulty = params.MinimumDifficulty +// genesis.GasLimit = 25000000 + +// genesis.BaseFee = big.NewInt(params.InitialBaseFee) +// genesis.Config = params.AllEthashProtocolChanges +// genesis.Config.TerminalTotalDifficulty = transitionDifficulty + +// genesis.Alloc = core.GenesisAlloc{} +// for _, faucet := range faucets { +// genesis.Alloc[crypto.PubkeyToAddress(faucet.PublicKey)] = core.GenesisAccount{ +// Balance: new(big.Int).Exp(big.NewInt(2), big.NewInt(128), nil), +// } +// } + +// return genesis +// } + +// func makeFullNode(genesis *core.Genesis) (*node.Node, *eth.Ethereum, *ethcatalyst.ConsensusAPI, error) { +// // Define the basic configurations for the Ethereum node +// datadir, _ := os.MkdirTemp("", "") + +// config := &node.Config{ +// Name: "geth", +// Version: params.Version, +// DataDir: datadir, +// P2P: p2p.Config{ +// ListenAddr: "0.0.0.0:0", +// NoDiscovery: true, +// MaxPeers: 25, +// }, +// UseLightweightKDF: true, +// } +// // Create the node and configure a full Ethereum node on it +// stack, err := node.New(config) +// if err != nil { +// return nil, nil, nil, err +// } + +// econfig := ðconfig.Config{ +// Genesis: genesis, +// NetworkId: genesis.Config.ChainID.Uint64(), +// SyncMode: downloader.FullSync, +// DatabaseCache: 256, +// DatabaseHandles: 256, +// TxPool: txpool.DefaultConfig, +// GPO: ethconfig.Defaults.GPO, +// Ethash: ethconfig.Defaults.Ethash, +// Miner: miner.Config{ +// GasFloor: genesis.GasLimit * 9 / 10, +// GasCeil: genesis.GasLimit * 11 / 10, +// GasPrice: big.NewInt(1), +// Recommit: 1 * time.Second, +// }, +// LightServ: 100, +// LightPeers: 10, +// LightNoSyncServe: true, +// } + +// ethBackend, err := eth.New(stack, econfig) +// if err != nil { +// return nil, nil, nil, err +// } + +// _, err = les.NewLesServer(stack, ethBackend, econfig) +// if err != nil { +// log.Crit("Failed to create the LES server", "err", err) +// } + +// err = stack.Start() + +// return stack, ethBackend, ethcatalyst.NewConsensusAPI(ethBackend), err +// } + +// func makeLightNode(genesis *core.Genesis) (*node.Node, *les.LightEthereum, *lescatalyst.ConsensusAPI, error) { +// // Define the basic configurations for the Ethereum node +// datadir, _ := os.MkdirTemp("", "") + +// config := &node.Config{ +// Name: "geth", +// Version: params.Version, +// DataDir: datadir, +// P2P: p2p.Config{ +// ListenAddr: "0.0.0.0:0", +// NoDiscovery: true, +// MaxPeers: 25, +// }, +// UseLightweightKDF: true, +// } +// // Create the node and configure a full Ethereum node on it +// stack, err := node.New(config) +// if err != nil { +// return nil, nil, nil, err +// } + +// lesBackend, err := les.New(stack, ðconfig.Config{ +// Genesis: genesis, +// NetworkId: genesis.Config.ChainID.Uint64(), +// SyncMode: downloader.LightSync, +// DatabaseCache: 256, +// DatabaseHandles: 256, +// TxPool: txpool.DefaultConfig, +// GPO: ethconfig.Defaults.GPO, +// Ethash: ethconfig.Defaults.Ethash, +// LightPeers: 10, +// }) +// if err != nil { +// return nil, nil, nil, err +// } + +// err = stack.Start() + +// return stack, lesBackend, lescatalyst.NewConsensusAPI(lesBackend), err +// } + +// func eth2types(typ nodetype) bool { +// if typ == eth2LightClient || typ == eth2NormalNode || typ == eth2MiningNode { +// return true +// } + +// return false +// } diff --git a/packaging/templates/package_scripts/control b/packaging/templates/package_scripts/control index aaecd85740..7ef6e2cf2c 100644 --- a/packaging/templates/package_scripts/control +++ b/packaging/templates/package_scripts/control @@ -1,5 +1,5 @@ Source: bor -Version: 1.0.6 +Version: 1.1.0-beta4 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.arm64 b/packaging/templates/package_scripts/control.arm64 index 32d014ed57..163f97777b 100644 --- a/packaging/templates/package_scripts/control.arm64 +++ b/packaging/templates/package_scripts/control.arm64 @@ -1,5 +1,5 @@ Source: bor -Version: 1.0.6 +Version: 1.1.0-beta4 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.amd64 b/packaging/templates/package_scripts/control.profile.amd64 index a51a03803e..295bc86751 100644 --- a/packaging/templates/package_scripts/control.profile.amd64 +++ b/packaging/templates/package_scripts/control.profile.amd64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.0.6 +Version: 1.1.0-beta4 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.arm64 b/packaging/templates/package_scripts/control.profile.arm64 index 0d1da4ede5..8f357dfde8 100644 --- a/packaging/templates/package_scripts/control.profile.arm64 +++ b/packaging/templates/package_scripts/control.profile.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.0.6 +Version: 1.1.0-beta4 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator b/packaging/templates/package_scripts/control.validator index 7c1405194a..8fbb02bcd9 100644 --- a/packaging/templates/package_scripts/control.validator +++ b/packaging/templates/package_scripts/control.validator @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.0.6 +Version: 1.1.0-beta4 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator.arm64 b/packaging/templates/package_scripts/control.validator.arm64 index 1412d9325e..498fab58db 100644 --- a/packaging/templates/package_scripts/control.validator.arm64 +++ b/packaging/templates/package_scripts/control.validator.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.0.6 +Version: 1.1.0-beta4 Section: develop Priority: standard Maintainer: Polygon diff --git a/params/config.go b/params/config.go index 8f54f1cb30..e3740068c6 100644 --- a/params/config.go +++ b/params/config.go @@ -81,7 +81,6 @@ var ( GrayGlacierBlock: big.NewInt(15_050_000), TerminalTotalDifficulty: MainnetTerminalTotalDifficulty, // 58_750_000_000_000_000_000_000 TerminalTotalDifficultyPassed: true, - ShanghaiTime: newUint64(1681338455), Ethash: new(EthashConfig), } @@ -125,7 +124,6 @@ var ( TerminalTotalDifficulty: big.NewInt(17_000_000_000_000_000), TerminalTotalDifficultyPassed: true, MergeNetsplitBlock: big.NewInt(1735371), - ShanghaiTime: newUint64(1677557088), Ethash: new(EthashConfig), } @@ -199,7 +197,6 @@ var ( ArrowGlacierBlock: nil, TerminalTotalDifficulty: big.NewInt(10_790_000), TerminalTotalDifficultyPassed: true, - ShanghaiTime: newUint64(1678832736), Clique: &CliqueConfig{ Period: 15, Epoch: 30000, @@ -316,6 +313,7 @@ var ( MuirGlacierBlock: big.NewInt(2722000), BerlinBlock: big.NewInt(13996000), LondonBlock: big.NewInt(22640000), + ShanghaiBlock: big.NewInt(41874000), Bor: &BorConfig{ JaipurBlock: big.NewInt(22770000), DelhiBlock: big.NewInt(29638656), @@ -346,6 +344,7 @@ var ( StateReceiverContract: "0x0000000000000000000000000000000000001001", BurntContract: map[string]string{ "22640000": "0x70bcA57F4579f58670aB2d18Ef16e02C17553C38", + "41874000": "0x617b94CCCC2511808A3C9478ebb96f455CF167aA", }, BlockAlloc: map[string]interface{}{ // write as interface since that is how it is decoded in genesis @@ -355,6 +354,12 @@ var ( "code": "0x60806040526004361061019c5760003560e01c806377d32e94116100ec578063acd06cb31161008a578063e306f77911610064578063e306f77914610a7b578063e614d0d614610aa6578063f2fde38b14610ad1578063fc0c546a14610b225761019c565b8063acd06cb31461097a578063b789543c146109cd578063cc79f97b14610a505761019c565b80639025e64c116100c65780639025e64c146107c957806395d89b4114610859578063a9059cbb146108e9578063abceeba21461094f5761019c565b806377d32e94146106315780638da5cb5b146107435780638f32d59b1461079a5761019c565b806347e7ef24116101595780637019d41a116101335780637019d41a1461053357806370a082311461058a578063715018a6146105ef578063771282f6146106065761019c565b806347e7ef2414610410578063485cc9551461046b57806360f96a8f146104dc5761019c565b806306fdde03146101a15780631499c5921461023157806318160ddd1461028257806319d27d9c146102ad5780632e1a7d4d146103b1578063313ce567146103df575b600080fd5b3480156101ad57600080fd5b506101b6610b79565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101f65780820151818401526020810190506101db565b50505050905090810190601f1680156102235780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561023d57600080fd5b506102806004803603602081101561025457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610bb6565b005b34801561028e57600080fd5b50610297610c24565b6040518082815260200191505060405180910390f35b3480156102b957600080fd5b5061036f600480360360a08110156102d057600080fd5b81019080803590602001906401000000008111156102ed57600080fd5b8201836020820111156102ff57600080fd5b8035906020019184600183028401116401000000008311171561032157600080fd5b9091929391929390803590602001909291908035906020019092919080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610c3a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6103dd600480360360208110156103c757600080fd5b8101908080359060200190929190505050610caa565b005b3480156103eb57600080fd5b506103f4610dfc565b604051808260ff1660ff16815260200191505060405180910390f35b34801561041c57600080fd5b506104696004803603604081101561043357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610e05565b005b34801561047757600080fd5b506104da6004803603604081101561048e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610fc1565b005b3480156104e857600080fd5b506104f1611090565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561053f57600080fd5b506105486110b6565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561059657600080fd5b506105d9600480360360208110156105ad57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506110dc565b6040518082815260200191505060405180910390f35b3480156105fb57600080fd5b506106046110fd565b005b34801561061257600080fd5b5061061b6111cd565b6040518082815260200191505060405180910390f35b34801561063d57600080fd5b506107016004803603604081101561065457600080fd5b81019080803590602001909291908035906020019064010000000081111561067b57600080fd5b82018360208201111561068d57600080fd5b803590602001918460018302840111640100000000831117156106af57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506111d3565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561074f57600080fd5b50610758611358565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156107a657600080fd5b506107af611381565b604051808215151515815260200191505060405180910390f35b3480156107d557600080fd5b506107de6113d8565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561081e578082015181840152602081019050610803565b50505050905090810190601f16801561084b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561086557600080fd5b5061086e611411565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156108ae578082015181840152602081019050610893565b50505050905090810190601f1680156108db5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610935600480360360408110156108ff57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061144e565b604051808215151515815260200191505060405180910390f35b34801561095b57600080fd5b50610964611474565b6040518082815260200191505060405180910390f35b34801561098657600080fd5b506109b36004803603602081101561099d57600080fd5b8101908080359060200190929190505050611501565b604051808215151515815260200191505060405180910390f35b3480156109d957600080fd5b50610a3a600480360360808110156109f057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291908035906020019092919080359060200190929190505050611521565b6040518082815260200191505060405180910390f35b348015610a5c57600080fd5b50610a65611541565b6040518082815260200191505060405180910390f35b348015610a8757600080fd5b50610a90611548565b6040518082815260200191505060405180910390f35b348015610ab257600080fd5b50610abb61154e565b6040518082815260200191505060405180910390f35b348015610add57600080fd5b50610b2060048036036020811015610af457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506115db565b005b348015610b2e57600080fd5b50610b376115f8565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b60606040518060400160405280600b81526020017f4d6174696320546f6b656e000000000000000000000000000000000000000000815250905090565b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260108152602001807f44697361626c656420666561747572650000000000000000000000000000000081525060200191505060405180910390fd5b6000601260ff16600a0a6402540be40002905090565b60006040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260108152602001807f44697361626c656420666561747572650000000000000000000000000000000081525060200191505060405180910390fd5b60003390506000610cba826110dc565b9050610cd18360065461161e90919063ffffffff16565b600681905550600083118015610ce657508234145b610d58576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f496e73756666696369656e7420616d6f756e740000000000000000000000000081525060200191505060405180910390fd5b8173ffffffffffffffffffffffffffffffffffffffff16600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167febff2602b3f468259e1e99f613fed6691f3a6526effe6ef3e768ba7ae7a36c4f8584610dd4876110dc565b60405180848152602001838152602001828152602001935050505060405180910390a3505050565b60006012905090565b610e0d611381565b610e1657600080fd5b600081118015610e535750600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b610ea8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180611da96023913960400191505060405180910390fd5b6000610eb3836110dc565b905060008390508073ffffffffffffffffffffffffffffffffffffffff166108fc849081150290604051600060405180830381858888f19350505050158015610f00573d6000803e3d6000fd5b50610f168360065461163e90919063ffffffff16565b6006819055508373ffffffffffffffffffffffffffffffffffffffff16600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f4e2ca0515ed1aef1395f66b5303bb5d6f1bf9d61a353fa53f73f8ac9973fa9f68585610f98896110dc565b60405180848152602001838152602001828152602001935050505060405180910390a350505050565b600760009054906101000a900460ff1615611027576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180611d866023913960400191505060405180910390fd5b6001600760006101000a81548160ff02191690831515021790555080600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555061108c8261165d565b5050565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008173ffffffffffffffffffffffffffffffffffffffff16319050919050565b611105611381565b61110e57600080fd5b600073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60065481565b60008060008060418551146111ee5760009350505050611352565b602085015192506040850151915060ff6041860151169050601b8160ff16101561121957601b810190505b601b8160ff16141580156112315750601c8160ff1614155b156112425760009350505050611352565b60018682858560405160008152602001604052604051808581526020018460ff1660ff1681526020018381526020018281526020019450505050506020604051602081039080840390855afa15801561129f573d6000803e3d6000fd5b505050602060405103519350600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16141561134e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f4572726f7220696e2065637265636f766572000000000000000000000000000081525060200191505060405180910390fd5b5050505b92915050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614905090565b6040518060400160405280600381526020017f013881000000000000000000000000000000000000000000000000000000000081525081565b60606040518060400160405280600581526020017f4d41544943000000000000000000000000000000000000000000000000000000815250905090565b6000813414611460576000905061146e565b61146b338484611755565b90505b92915050565b6040518060800160405280605b8152602001611e1e605b91396040516020018082805190602001908083835b602083106114c357805182526020820191506020810190506020830392506114a0565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040516020818303038152906040528051906020012081565b60056020528060005260406000206000915054906101000a900460ff1681565b600061153761153286868686611b12565b611be8565b9050949350505050565b6201388181565b60015481565b604051806080016040528060528152602001611dcc605291396040516020018082805190602001908083835b6020831061159d578051825260208201915060208101905060208303925061157a565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040516020818303038152906040528051906020012081565b6115e3611381565b6115ec57600080fd5b6115f58161165d565b50565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008282111561162d57600080fd5b600082840390508091505092915050565b60008082840190508381101561165357600080fd5b8091505092915050565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561169757600080fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000803073ffffffffffffffffffffffffffffffffffffffff166370a08231866040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b1580156117d557600080fd5b505afa1580156117e9573d6000803e3d6000fd5b505050506040513d60208110156117ff57600080fd5b8101908080519060200190929190505050905060003073ffffffffffffffffffffffffffffffffffffffff166370a08231866040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b15801561189157600080fd5b505afa1580156118a5573d6000803e3d6000fd5b505050506040513d60208110156118bb57600080fd5b810190808051906020019092919050505090506118d9868686611c32565b8473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff16600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fe6497e3ee548a3372136af2fcb0696db31fc6cf20260707645068bd3fe97f3c48786863073ffffffffffffffffffffffffffffffffffffffff166370a082318e6040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b1580156119e157600080fd5b505afa1580156119f5573d6000803e3d6000fd5b505050506040513d6020811015611a0b57600080fd5b81019080805190602001909291905050503073ffffffffffffffffffffffffffffffffffffffff166370a082318e6040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015611a9957600080fd5b505afa158015611aad573d6000803e3d6000fd5b505050506040513d6020811015611ac357600080fd5b8101908080519060200190929190505050604051808681526020018581526020018481526020018381526020018281526020019550505050505060405180910390a46001925050509392505050565b6000806040518060800160405280605b8152602001611e1e605b91396040516020018082805190602001908083835b60208310611b645780518252602082019150602081019050602083039250611b41565b6001836020036101000a03801982511681845116808217855250505050505090500191505060405160208183030381529060405280519060200120905060405181815273ffffffffffffffffffffffffffffffffffffffff8716602082015285604082015284606082015283608082015260a0812092505081915050949350505050565b60008060015490506040517f190100000000000000000000000000000000000000000000000000000000000081528160028201528360228201526042812092505081915050919050565b3073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611cd4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f63616e27742073656e6420746f204d524332300000000000000000000000000081525060200191505060405180910390fd5b8173ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f19350505050158015611d1a573d6000803e3d6000fd5b508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a350505056fe54686520636f6e747261637420697320616c726561647920696e697469616c697a6564496e73756666696369656e7420616d6f756e74206f7220696e76616c69642075736572454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c75696e7432353620636861696e49642c6164647265737320766572696679696e67436f6e747261637429546f6b656e5472616e736665724f726465722861646472657373207370656e6465722c75696e7432353620746f6b656e49644f72416d6f756e742c6279746573333220646174612c75696e743235362065787069726174696f6e29a265627a7a72315820ccd6c2a9c259832bbb367986ee06cd87af23022681b0cb22311a864b701d939564736f6c63430005100032", }, }, + "41874000": map[string]interface{}{ + "0x0000000000000000000000000000000000001001": map[string]interface{}{ + "balance": "0x0", + "code": "0x608060405234801561001057600080fd5b506004361061005e576000357c01000000000000000000000000000000000000000000000000000000009004806319494a17146100635780633434735f146100fe5780635407ca6714610148575b600080fd5b6100e46004803603604081101561007957600080fd5b8101908080359060200190929190803590602001906401000000008111156100a057600080fd5b8201836020820111156100b257600080fd5b803590602001918460018302840111640100000000831117156100d457600080fd5b9091929391929390505050610166565b604051808215151515815260200191505060405180910390f35b6101066104d3565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6101506104eb565b6040518082815260200191505060405180910390f35b600073fffffffffffffffffffffffffffffffffffffffe73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461021d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f4e6f742053797374656d2041646465737321000000000000000000000000000081525060200191505060405180910390fd5b606061027461026f85858080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050506104f1565b61051f565b905060006102958260008151811061028857fe5b60200260200101516105fc565b90508060016000540114610311576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f537461746549647320617265206e6f742073657175656e7469616c000000000081525060200191505060405180910390fd5b600080815480929190600101919050555060006103418360018151811061033457fe5b602002602001015161066d565b905060606103628460028151811061035557fe5b6020026020010151610690565b905061036d8261071c565b156104c8576000624c4b409050606084836040516024018083815260200180602001828103825283818151815260200191508051906020019080838360005b838110156103c75780820151818401526020810190506103ac565b50505050905090810190601f1680156103f45780820380516001836020036101000a031916815260200191505b5093505050506040516020818303038152906040527f26c53bea000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050905060008082516020840160008887f19650847f5a22725590b0a51c923940223f7458512164b1113359a735e86e7f27f44791ee88604051808215151515815260200191505060405180910390a250505b505050509392505050565b73fffffffffffffffffffffffffffffffffffffffe81565b60005481565b6104f961099c565b600060208301905060405180604001604052808451815260200182815250915050919050565b606061052a82610735565b61053357600080fd5b600061053e83610783565b905060608160405190808252806020026020018201604052801561057c57816020015b6105696109b6565b8152602001906001900390816105615790505b509050600061058e85602001516107f4565b8560200151019050600080600090505b848110156105ef576105af8361087d565b91506040518060400160405280838152602001848152508482815181106105d257fe5b60200260200101819052508183019250808060010191505061059e565b5082945050505050919050565b600080826000015111801561061657506021826000015111155b61061f57600080fd5b600061062e83602001516107f4565b9050600081846000015103905060008083866020015101905080519150602083101561066157826020036101000a820491505b81945050505050919050565b6000601582600001511461068057600080fd5b610689826105fc565b9050919050565b606060008260000151116106a357600080fd5b60006106b283602001516107f4565b905060008184600001510390506060816040519080825280601f01601f1916602001820160405280156106f45781602001600182028038833980820191505090505b5090506000816020019050610710848760200151018285610935565b81945050505050919050565b600080823b905060008163ffffffff1611915050919050565b6000808260000151141561074c576000905061077e565b60008083602001519050805160001a915060c060ff168260ff1610156107775760009250505061077e565b6001925050505b919050565b6000808260000151141561079a57600090506107ef565b600080905060006107ae84602001516107f4565b84602001510190506000846000015185602001510190505b808210156107e8576107d78261087d565b8201915082806001019350506107c6565b8293505050505b919050565b600080825160001a9050608060ff16811015610814576000915050610878565b60b860ff16811080610839575060c060ff168110158015610838575060f860ff1681105b5b15610848576001915050610878565b60c060ff168110156108685760018060b80360ff16820301915050610878565b60018060f80360ff168203019150505b919050565b6000806000835160001a9050608060ff1681101561089e576001915061092b565b60b860ff168110156108bb576001608060ff16820301915061092a565b60c060ff168110156108eb5760b78103600185019450806020036101000a85510460018201810193505050610929565b60f860ff1681101561090857600160c060ff168203019150610928565b60f78103600185019450806020036101000a855104600182018101935050505b5b5b5b8192505050919050565b600081141561094357610997565b5b602060ff1681106109735782518252602060ff1683019250602060ff1682019150602060ff1681039050610944565b6000600182602060ff16036101000a03905080198451168184511681811785525050505b505050565b604051806040016040528060008152602001600081525090565b60405180604001604052806000815260200160008152509056fea265627a7a723158208f1ea6fcf63d6911ac5dbfe340be1029614581802c6a750e7d6354b32ce6647c64736f6c63430005110032", + }, + }, }, }, } @@ -445,9 +450,9 @@ var ( ArrowGlacierBlock: big.NewInt(0), GrayGlacierBlock: big.NewInt(0), MergeNetsplitBlock: nil, - ShanghaiTime: nil, - CancunTime: nil, - PragueTime: nil, + ShanghaiBlock: nil, + CancunBlock: nil, + PragueBlock: nil, TerminalTotalDifficulty: nil, TerminalTotalDifficultyPassed: false, Ethash: new(EthashConfig), @@ -475,9 +480,9 @@ var ( ArrowGlacierBlock: nil, GrayGlacierBlock: nil, MergeNetsplitBlock: nil, - ShanghaiTime: nil, - CancunTime: nil, - PragueTime: nil, + ShanghaiBlock: nil, + CancunBlock: nil, + PragueBlock: nil, TerminalTotalDifficulty: nil, TerminalTotalDifficultyPassed: false, Ethash: nil, @@ -505,9 +510,9 @@ var ( ArrowGlacierBlock: big.NewInt(0), GrayGlacierBlock: big.NewInt(0), MergeNetsplitBlock: nil, - ShanghaiTime: nil, - CancunTime: nil, - PragueTime: nil, + ShanghaiBlock: nil, + CancunBlock: nil, + PragueBlock: nil, TerminalTotalDifficulty: nil, TerminalTotalDifficultyPassed: false, Ethash: new(EthashConfig), @@ -538,9 +543,9 @@ var ( ArrowGlacierBlock: nil, GrayGlacierBlock: nil, MergeNetsplitBlock: nil, - ShanghaiTime: nil, - CancunTime: nil, - PragueTime: nil, + ShanghaiBlock: nil, + CancunBlock: nil, + PragueBlock: nil, TerminalTotalDifficulty: nil, TerminalTotalDifficultyPassed: false, Ethash: new(EthashConfig), @@ -640,10 +645,10 @@ type ChainConfig struct { MergeNetsplitBlock *big.Int `json:"mergeNetsplitBlock,omitempty"` // Virtual fork after The Merge to use as a network splitter // Fork scheduling was switched from blocks to timestamps here - - ShanghaiTime *uint64 `json:"shanghaiTime,omitempty"` // Shanghai switch time (nil = no fork, 0 = already on shanghai) - CancunTime *uint64 `json:"cancunTime,omitempty"` // Cancun switch time (nil = no fork, 0 = already on cancun) - PragueTime *uint64 `json:"pragueTime,omitempty"` // Prague switch time (nil = no fork, 0 = already on prague) + // Fork scheduling switched back to blockNumber in Bor + ShanghaiBlock *big.Int `json:"shanghaiBlock,omitempty"` // Shanghai switch Block (nil = no fork, 0 = already on shanghai) + CancunBlock *big.Int `json:"cancunBlock,omitempty"` // Cancun switch Block (nil = no fork, 0 = already on cancun) + PragueBlock *big.Int `json:"pragueBlock,omitempty"` // Prague switch Block (nil = no fork, 0 = already on prague) // TerminalTotalDifficulty is the amount of total difficulty reached by // the network that triggers the consensus upgrade. @@ -711,11 +716,11 @@ func (c *BorConfig) CalculateSprint(number uint64) uint64 { } func (c *BorConfig) CalculateBackupMultiplier(number uint64) uint64 { - return c.calculateBorConfigHelper(c.BackupMultiplier, number) + return borKeyValueConfigHelper(c.BackupMultiplier, number) } func (c *BorConfig) CalculatePeriod(number uint64) uint64 { - return c.calculateBorConfigHelper(c.Period, number) + return borKeyValueConfigHelper(c.Period, number) } func (c *BorConfig) IsJaipur(number *big.Int) bool { @@ -749,64 +754,34 @@ func (c *BorConfig) IsSprintStart(number uint64) bool { return number%c.CalculateSprint(number) == 0 } -func (c *BorConfig) calculateBorConfigHelper(field map[string]uint64, number uint64) uint64 { - keys := make([]string, 0, len(field)) - for k := range field { - keys = append(keys, k) - } - - sort.Strings(keys) - - for i := 0; i < len(keys)-1; i++ { - valUint, _ := strconv.ParseUint(keys[i], 10, 64) - valUintNext, _ := strconv.ParseUint(keys[i+1], 10, 64) +func borKeyValueConfigHelper[T uint64 | string](field map[string]T, number uint64) T { + keys := make([]uint64, 0, len(field)) + fieldUint := make(map[uint64]T) - if number > valUint && number < valUintNext { - return field[keys[i]] + for k, v := range field { + keyUint, err := strconv.ParseUint(k, 10, 64) + if err != nil { + panic(err) } - } - return field[keys[len(keys)-1]] -} + keys = append(keys, keyUint) -func borKeyValueConfigHelper(field map[string]uint64, number uint64) uint64 { - keys := make([]string, 0, len(field)) - for k := range field { - keys = append(keys, k) + fieldUint[keyUint] = v } - sort.Strings(keys) + sort.Slice(keys, func(i, j int) bool { return keys[i] < keys[j] }) for i := 0; i < len(keys)-1; i++ { - valUint, _ := strconv.ParseUint(keys[i], 10, 64) - valUintNext, _ := strconv.ParseUint(keys[i+1], 10, 64) - - if number >= valUint && number < valUintNext { - return field[keys[i]] + if number >= keys[i] && number < keys[i+1] { + return fieldUint[keys[i]] } } - return field[keys[len(keys)-1]] + return fieldUint[keys[len(keys)-1]] } func (c *BorConfig) CalculateBurntContract(number uint64) string { - keys := make([]string, 0, len(c.BurntContract)) - for k := range c.BurntContract { - keys = append(keys, k) - } - - sort.Strings(keys) - - for i := 0; i < len(keys)-1; i++ { - valUint, _ := strconv.ParseUint(keys[i], 10, 64) - valUintNext, _ := strconv.ParseUint(keys[i+1], 10, 64) - - if number > valUint && number < valUintNext { - return c.BurntContract[keys[i]] - } - } - - return c.BurntContract[keys[len(keys)-1]] + return borKeyValueConfigHelper(c.BurntContract, number) } // Description returns a human-readable description of ChainConfig. @@ -900,16 +875,16 @@ func (c *ChainConfig) Description() string { // Create a list of forks post-merge banner += "Post-Merge hard forks (timestamp based):\n" - if c.ShanghaiTime != nil { - banner += fmt.Sprintf(" - Shanghai: @%-10v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/shanghai.md)\n", *c.ShanghaiTime) + if c.ShanghaiBlock != nil { + banner += fmt.Sprintf(" - Shanghai: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/shanghai.md)\n", c.ShanghaiBlock) } - if c.CancunTime != nil { - banner += fmt.Sprintf(" - Cancun: @%-10v\n", *c.CancunTime) + if c.CancunBlock != nil { + banner += fmt.Sprintf(" - Cancun: #%-8v\n", c.CancunBlock) } - if c.PragueTime != nil { - banner += fmt.Sprintf(" - Prague: @%-10v\n", *c.PragueTime) + if c.PragueBlock != nil { + banner += fmt.Sprintf(" - Prague: #%-8v\n", c.PragueBlock) } return banner @@ -997,19 +972,18 @@ func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *bi } // IsShanghai returns whether time is either equal to the Shanghai fork time or greater. -// TODO marcello double check -func (c *ChainConfig) IsShanghai(time uint64) bool { - return isTimestampForked(c.ShanghaiTime, time) +func (c *ChainConfig) IsShanghai(num *big.Int) bool { + return isBlockForked(c.ShanghaiBlock, num) } // IsCancun returns whether num is either equal to the Cancun fork time or greater. -func (c *ChainConfig) IsCancun(time uint64) bool { - return isTimestampForked(c.CancunTime, time) +func (c *ChainConfig) IsCancun(num *big.Int) bool { + return isBlockForked(c.CancunBlock, num) } // IsPrague returns whether num is either equal to the Prague fork time or greater. -func (c *ChainConfig) IsPrague(time uint64) bool { - return isTimestampForked(c.PragueTime, time) +func (c *ChainConfig) IsPrague(num *big.Int) bool { + return isBlockForked(c.PragueBlock, num) } // CheckCompatible checks whether scheduled fork transitions have been imported @@ -1067,9 +1041,9 @@ func (c *ChainConfig) CheckConfigForkOrder() error { {name: "arrowGlacierBlock", block: c.ArrowGlacierBlock, optional: true}, {name: "grayGlacierBlock", block: c.GrayGlacierBlock, optional: true}, {name: "mergeNetsplitBlock", block: c.MergeNetsplitBlock, optional: true}, - {name: "shanghaiTime", timestamp: c.ShanghaiTime}, - {name: "cancunTime", timestamp: c.CancunTime, optional: true}, - {name: "pragueTime", timestamp: c.PragueTime, optional: true}, + {name: "shanghaiTime", block: c.ShanghaiBlock}, + {name: "cancunTime", block: c.CancunBlock, optional: true}, + {name: "pragueTime", block: c.PragueBlock, optional: true}, } { if lastFork.name != "" { switch { @@ -1182,16 +1156,16 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, headNumber *big.Int, return newBlockCompatError("Merge netsplit fork block", c.MergeNetsplitBlock, newcfg.MergeNetsplitBlock) } - if isForkTimestampIncompatible(c.ShanghaiTime, newcfg.ShanghaiTime, headTimestamp) { - return newTimestampCompatError("Shanghai fork timestamp", c.ShanghaiTime, newcfg.ShanghaiTime) + if isForkBlockIncompatible(c.ShanghaiBlock, newcfg.ShanghaiBlock, headNumber) { + return newBlockCompatError("Shanghai fork block", c.ShanghaiBlock, newcfg.ShanghaiBlock) } - if isForkTimestampIncompatible(c.CancunTime, newcfg.CancunTime, headTimestamp) { - return newTimestampCompatError("Cancun fork timestamp", c.CancunTime, newcfg.CancunTime) + if isForkBlockIncompatible(c.CancunBlock, newcfg.CancunBlock, headNumber) { + return newBlockCompatError("Cancun fork block", c.CancunBlock, newcfg.CancunBlock) } - if isForkTimestampIncompatible(c.PragueTime, newcfg.PragueTime, headTimestamp) { - return newTimestampCompatError("Prague fork timestamp", c.PragueTime, newcfg.PragueTime) + if isForkBlockIncompatible(c.PragueBlock, newcfg.PragueBlock, headNumber) { + return newBlockCompatError("Prague fork block", c.PragueBlock, newcfg.PragueBlock) } return nil @@ -1375,8 +1349,8 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules IsBerlin: c.IsBerlin(num), IsLondon: c.IsLondon(num), IsMerge: isMerge, - IsShanghai: c.IsShanghai(timestamp), - IsCancun: c.IsCancun(timestamp), - IsPrague: c.IsPrague(timestamp), + IsShanghai: c.IsShanghai(num), + IsCancun: c.IsCancun(num), + IsPrague: c.IsPrague(num), } } diff --git a/params/config_test.go b/params/config_test.go index 713fbaf880..10af3e28f7 100644 --- a/params/config_test.go +++ b/params/config_test.go @@ -22,6 +22,8 @@ import ( "testing" "time" + "gotest.tools/assert" + "github.com/ethereum/go-ethereum/common/math" ) @@ -94,22 +96,11 @@ func TestCheckCompatible(t *testing.T) { }, }, { - stored: &ChainConfig{ShanghaiTime: newUint64(10)}, - new: &ChainConfig{ShanghaiTime: newUint64(20)}, + stored: &ChainConfig{ShanghaiBlock: big.NewInt(30)}, + new: &ChainConfig{ShanghaiBlock: big.NewInt(30)}, headTimestamp: 9, wantErr: nil, }, - { - stored: &ChainConfig{ShanghaiTime: newUint64(10)}, - new: &ChainConfig{ShanghaiTime: newUint64(20)}, - headTimestamp: 25, - wantErr: &ConfigCompatError{ - What: "Shanghai fork timestamp", - StoredTime: newUint64(10), - NewTime: newUint64(20), - RewindToTime: 9, - }, - }, } for _, test := range tests { @@ -124,24 +115,66 @@ func TestConfigRules(t *testing.T) { t.Parallel() c := &ChainConfig{ - ShanghaiTime: newUint64(500), + ShanghaiBlock: big.NewInt(10), + } + + block := new(big.Int) + + if r := c.Rules(block, true, 0); r.IsShanghai { + t.Errorf("expected %v to not be shanghai", 0) } - var stamp uint64 + block.SetInt64(10) - if r := c.Rules(big.NewInt(0), true, stamp); r.IsShanghai { - t.Errorf("expected %v to not be shanghai", stamp) + if r := c.Rules(block, true, 0); !r.IsShanghai { + t.Errorf("expected %v to be shanghai", 0) } - stamp = 500 + block = block.SetInt64(math.MaxInt64) - if r := c.Rules(big.NewInt(0), true, stamp); !r.IsShanghai { - t.Errorf("expected %v to be shanghai", stamp) + if r := c.Rules(block, true, 0); !r.IsShanghai { + t.Errorf("expected %v to be shanghai", 0) } +} + +func TestBorKeyValueConfigHelper(t *testing.T) { + t.Parallel() - stamp = math.MaxInt64 + backupMultiplier := map[string]uint64{ + "0": 2, + "25275000": 5, + "29638656": 2, + } + assert.Equal(t, borKeyValueConfigHelper(backupMultiplier, 0), uint64(2)) + assert.Equal(t, borKeyValueConfigHelper(backupMultiplier, 1), uint64(2)) + assert.Equal(t, borKeyValueConfigHelper(backupMultiplier, 25275000-1), uint64(2)) + assert.Equal(t, borKeyValueConfigHelper(backupMultiplier, 25275000), uint64(5)) + assert.Equal(t, borKeyValueConfigHelper(backupMultiplier, 25275000+1), uint64(5)) + assert.Equal(t, borKeyValueConfigHelper(backupMultiplier, 29638656-1), uint64(5)) + assert.Equal(t, borKeyValueConfigHelper(backupMultiplier, 29638656), uint64(2)) + assert.Equal(t, borKeyValueConfigHelper(backupMultiplier, 29638656+1), uint64(2)) + + config := map[string]uint64{ + "0": 1, + "90000000": 2, + "100000000": 3, + } + assert.Equal(t, borKeyValueConfigHelper(config, 0), uint64(1)) + assert.Equal(t, borKeyValueConfigHelper(config, 1), uint64(1)) + assert.Equal(t, borKeyValueConfigHelper(config, 90000000-1), uint64(1)) + assert.Equal(t, borKeyValueConfigHelper(config, 90000000), uint64(2)) + assert.Equal(t, borKeyValueConfigHelper(config, 90000000+1), uint64(2)) + assert.Equal(t, borKeyValueConfigHelper(config, 100000000-1), uint64(2)) + assert.Equal(t, borKeyValueConfigHelper(config, 100000000), uint64(3)) + assert.Equal(t, borKeyValueConfigHelper(config, 100000000+1), uint64(3)) - if r := c.Rules(big.NewInt(0), true, stamp); !r.IsShanghai { - t.Errorf("expected %v to be shanghai", stamp) + burntContract := map[string]string{ + "22640000": "0x70bcA57F4579f58670aB2d18Ef16e02C17553C38", + "41824608": "0x617b94CCCC2511808A3C9478ebb96f455CF167aA", } + assert.Equal(t, borKeyValueConfigHelper(burntContract, 22640000), "0x70bcA57F4579f58670aB2d18Ef16e02C17553C38") + assert.Equal(t, borKeyValueConfigHelper(burntContract, 22640000+1), "0x70bcA57F4579f58670aB2d18Ef16e02C17553C38") + assert.Equal(t, borKeyValueConfigHelper(burntContract, 41824608-1), "0x70bcA57F4579f58670aB2d18Ef16e02C17553C38") + assert.Equal(t, borKeyValueConfigHelper(burntContract, 41824608), "0x617b94CCCC2511808A3C9478ebb96f455CF167aA") + assert.Equal(t, borKeyValueConfigHelper(burntContract, 41824608+1), "0x617b94CCCC2511808A3C9478ebb96f455CF167aA") } diff --git a/params/version.go b/params/version.go index 6e09af0ad9..ff36680892 100644 --- a/params/version.go +++ b/params/version.go @@ -21,10 +21,10 @@ import ( ) const ( - VersionMajor = 1 // Major version component of the current release - VersionMinor = 0 // Minor version component of the current release - VersionPatch = 6 // Patch version component of the current release - VersionMeta = "" // Version metadata to append to the version string + VersionMajor = 1 // Major version component of the current release + VersionMinor = 1 // Minor version component of the current release + VersionPatch = 0 // Patch version component of the current release + VersionMeta = "beta4" // Version metadata to append to the version string ) var GitCommit string diff --git a/tests/bor/bor_test.go b/tests/bor/bor_test.go index 9981283fe4..683c66c453 100644 --- a/tests/bor/bor_test.go +++ b/tests/bor/bor_test.go @@ -969,6 +969,290 @@ func TestEIP1559Transition(t *testing.T) { } } +func TestBurnContract(t *testing.T) { + var ( + aa = common.HexToAddress("0x000000000000000000000000000000000000aaaa") + + // Generate a canonical chain to act as the main dataset + db = rawdb.NewMemoryDatabase() + engine = ethash.NewFaker() + + // A sender who makes transactions, has some funds + key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") + key2, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a") + key3, _ = crypto.HexToECDSA("225171aed3793cba1c029832886d69785b7e77a54a44211226b447aa2d16b058") + + addr1 = crypto.PubkeyToAddress(key1.PublicKey) + addr2 = crypto.PubkeyToAddress(key2.PublicKey) + addr3 = crypto.PubkeyToAddress(key3.PublicKey) + funds = new(big.Int).Mul(common.Big1, big.NewInt(params.Ether)) + gspec = &core.Genesis{ + Config: params.BorUnittestChainConfig, + Alloc: core.GenesisAlloc{ + addr1: {Balance: funds}, + addr2: {Balance: funds}, + addr3: {Balance: funds}, + // The address 0xAAAA sloads 0x00 and 0x01 + aa: { + Code: []byte{ + byte(vm.PC), + byte(vm.PC), + byte(vm.SLOAD), + byte(vm.SLOAD), + }, + Nonce: 0, + Balance: big.NewInt(0), + }, + }, + } + ) + + gspec.Config.BerlinBlock = common.Big0 + gspec.Config.LondonBlock = common.Big0 + gspec.Config.Bor.BurntContract = map[string]string{ + "0": "0x000000000000000000000000000000000000aaab", + "1": "0x000000000000000000000000000000000000aaac", + "2": "0x000000000000000000000000000000000000aaad", + "3": "0x000000000000000000000000000000000000aaae", + } + genesis := gspec.MustCommit(db) + signer := types.LatestSigner(gspec.Config) + + blocks, _ := core.GenerateChain(gspec.Config, genesis, engine, db, 1, func(i int, b *core.BlockGen) { + b.SetCoinbase(common.Address{1}) + // One transaction to 0xAAAA + accesses := types.AccessList{types.AccessTuple{ + Address: aa, + StorageKeys: []common.Hash{{0}}, + }} + + txdata := &types.DynamicFeeTx{ + ChainID: gspec.Config.ChainID, + Nonce: 0, + To: &aa, + Gas: 30000, + GasFeeCap: newGwei(5), + GasTipCap: big.NewInt(2), + AccessList: accesses, + Data: []byte{}, + } + tx := types.NewTx(txdata) + tx, _ = types.SignTx(tx, signer, key1) + + b.AddTx(tx) + }) + + diskdb := rawdb.NewMemoryDatabase() + gspec.MustCommit(diskdb) + + chain, err := core.NewBlockChain(diskdb, nil, gspec, nil, engine, vm.Config{}, nil, nil, nil) + if err != nil { + t.Fatalf("failed to create tester chain: %v", err) + } + if n, err := chain.InsertChain(blocks); err != nil { + t.Fatalf("block %d: failed to insert into chain: %v", n, err) + } + + block := chain.GetBlockByNumber(1) + + // 1+2: Ensure EIP-1559 access lists are accounted for via gas usage. + expectedGas := params.TxGas + params.TxAccessListAddressGas + params.TxAccessListStorageKeyGas + + vm.GasQuickStep*2 + params.WarmStorageReadCostEIP2929 + params.ColdSloadCostEIP2929 + if block.GasUsed() != expectedGas { + t.Fatalf("incorrect amount of gas spent: expected %d, got %d", expectedGas, block.GasUsed()) + } + + state, _ := chain.State() + + // 3: Ensure that miner received only the tx's tip. + actual := state.GetBalance(block.Coinbase()) + expected := new(big.Int).Add( + new(big.Int).SetUint64(block.GasUsed()*block.Transactions()[0].GasTipCap().Uint64()), + ethash.ConstantinopleBlockReward, + ) + if actual.Cmp(expected) != 0 { + t.Fatalf("miner balance incorrect: expected %d, got %d", expected, actual) + } + + // check burnt contract balance + actual = state.GetBalance(common.HexToAddress(gspec.Config.Bor.CalculateBurntContract(block.NumberU64()))) + expected = new(big.Int).Mul(new(big.Int).SetUint64(block.GasUsed()), block.BaseFee()) + if actual.Cmp(expected) != 0 { + t.Fatalf("burnt contract balance incorrect: expected %d, got %d", expected, actual) + } + + // 4: Ensure the tx sender paid for the gasUsed * (tip + block baseFee). + actual = new(big.Int).Sub(funds, state.GetBalance(addr1)) + expected = new(big.Int).SetUint64(block.GasUsed() * (block.Transactions()[0].GasTipCap().Uint64() + block.BaseFee().Uint64())) + if actual.Cmp(expected) != 0 { + t.Fatalf("sender balance incorrect: expected %d, got %d", expected, actual) + } + + blocks, _ = core.GenerateChain(gspec.Config, block, engine, db, 1, func(i int, b *core.BlockGen) { + b.SetCoinbase(common.Address{2}) + + txdata := &types.LegacyTx{ + Nonce: 0, + To: &aa, + Gas: 30000, + GasPrice: newGwei(5), + } + tx := types.NewTx(txdata) + tx, _ = types.SignTx(tx, signer, key2) + + b.AddTx(tx) + }) + + if n, err := chain.InsertChain(blocks); err != nil { + t.Fatalf("block %d: failed to insert into chain: %v", n, err) + } + + block = chain.GetBlockByNumber(2) + state, _ = chain.State() + effectiveTip := block.Transactions()[0].GasTipCap().Uint64() - block.BaseFee().Uint64() + + // 6+5: Ensure that miner received only the tx's effective tip. + actual = state.GetBalance(block.Coinbase()) + expected = new(big.Int).Add( + new(big.Int).SetUint64(block.GasUsed()*effectiveTip), + ethash.ConstantinopleBlockReward, + ) + if actual.Cmp(expected) != 0 { + t.Fatalf("miner balance incorrect: expected %d, got %d", expected, actual) + } + + // check burnt contract balance + actual = state.GetBalance(common.HexToAddress(gspec.Config.Bor.CalculateBurntContract(block.NumberU64()))) + expected = new(big.Int).Mul(new(big.Int).SetUint64(block.GasUsed()), block.BaseFee()) + if actual.Cmp(expected) != 0 { + t.Fatalf("burnt contract balance incorrect: expected %d, got %d", expected, actual) + } + + // 4: Ensure the tx sender paid for the gasUsed * (effectiveTip + block baseFee). + actual = new(big.Int).Sub(funds, state.GetBalance(addr2)) + expected = new(big.Int).SetUint64(block.GasUsed() * (effectiveTip + block.BaseFee().Uint64())) + if actual.Cmp(expected) != 0 { + t.Fatalf("sender balance incorrect: expected %d, got %d", expected, actual) + } + + blocks, _ = core.GenerateChain(gspec.Config, block, engine, db, 1, func(i int, b *core.BlockGen) { + b.SetCoinbase(common.Address{3}) + + txdata := &types.LegacyTx{ + Nonce: 0, + To: &aa, + Gas: 30000, + GasPrice: newGwei(5), + } + tx := types.NewTx(txdata) + tx, _ = types.SignTx(tx, signer, key3) + + b.AddTx(tx) + }) + + if n, err := chain.InsertChain(blocks); err != nil { + t.Fatalf("block %d: failed to insert into chain: %v", n, err) + } + + block = chain.GetBlockByNumber(3) + state, _ = chain.State() + effectiveTip = block.Transactions()[0].GasTipCap().Uint64() - block.BaseFee().Uint64() + + // 6+5: Ensure that miner received only the tx's effective tip. + actual = state.GetBalance(block.Coinbase()) + expected = new(big.Int).Add( + new(big.Int).SetUint64(block.GasUsed()*effectiveTip), + ethash.ConstantinopleBlockReward, + ) + if actual.Cmp(expected) != 0 { + t.Fatalf("miner balance incorrect: expected %d, got %d", expected, actual) + } + + // check burnt contract balance + actual = state.GetBalance(common.HexToAddress(gspec.Config.Bor.CalculateBurntContract(block.NumberU64()))) + expected = new(big.Int).Mul(new(big.Int).SetUint64(block.GasUsed()), block.BaseFee()) + if actual.Cmp(expected) != 0 { + t.Fatalf("burnt contract balance incorrect: expected %d, got %d", expected, actual) + } + + // 4: Ensure the tx sender paid for the gasUsed * (effectiveTip + block baseFee). + actual = new(big.Int).Sub(funds, state.GetBalance(addr3)) + expected = new(big.Int).SetUint64(block.GasUsed() * (effectiveTip + block.BaseFee().Uint64())) + if actual.Cmp(expected) != 0 { + t.Fatalf("sender balance incorrect: expected %d, got %d", expected, actual) + } +} + +func TestBurnContractContractFetch(t *testing.T) { + config := params.BorUnittestChainConfig + config.Bor.BurntContract = map[string]string{ + "10": "0x000000000000000000000000000000000000aaab", + "100": "0x000000000000000000000000000000000000aaad", + } + + burnContractAddr10 := config.Bor.CalculateBurntContract(10) + burnContractAddr11 := config.Bor.CalculateBurntContract(11) + burnContractAddr99 := config.Bor.CalculateBurntContract(99) + burnContractAddr100 := config.Bor.CalculateBurntContract(100) + burnContractAddr101 := config.Bor.CalculateBurntContract(101) + + if burnContractAddr10 != "0x000000000000000000000000000000000000aaab" { + t.Fatalf("incorrect burnt contract address: expected %s, got %s", "0x000000000000000000000000000000000000aaab", burnContractAddr10) + } + if burnContractAddr11 != "0x000000000000000000000000000000000000aaab" { + t.Fatalf("incorrect burnt contract address: expected %s, got %s", "0x000000000000000000000000000000000000aaab", burnContractAddr11) + } + if burnContractAddr99 != "0x000000000000000000000000000000000000aaab" { + t.Fatalf("incorrect burnt contract address: expected %s, got %s", "0x000000000000000000000000000000000000aaab", burnContractAddr99) + } + if burnContractAddr100 != "0x000000000000000000000000000000000000aaad" { + t.Fatalf("incorrect burnt contract address: expected %s, got %s", "0x000000000000000000000000000000000000aaad", burnContractAddr100) + } + if burnContractAddr101 != "0x000000000000000000000000000000000000aaad" { + t.Fatalf("incorrect burnt contract address: expected %s, got %s", "0x000000000000000000000000000000000000aaad", burnContractAddr101) + } + + config.Bor.BurntContract = map[string]string{ + "10": "0x000000000000000000000000000000000000aaab", + "100": "0x000000000000000000000000000000000000aaad", + "1000": "0x000000000000000000000000000000000000aaae", + } + + burnContractAddr10 = config.Bor.CalculateBurntContract(10) + burnContractAddr11 = config.Bor.CalculateBurntContract(11) + burnContractAddr99 = config.Bor.CalculateBurntContract(99) + burnContractAddr100 = config.Bor.CalculateBurntContract(100) + burnContractAddr101 = config.Bor.CalculateBurntContract(101) + burnContractAddr999 := config.Bor.CalculateBurntContract(999) + burnContractAddr1000 := config.Bor.CalculateBurntContract(1000) + burnContractAddr1001 := config.Bor.CalculateBurntContract(1001) + + if burnContractAddr10 != "0x000000000000000000000000000000000000aaab" { + t.Fatalf("incorrect burnt contract address: expected %s, got %s", "0x000000000000000000000000000000000000aaab", burnContractAddr10) + } + if burnContractAddr11 != "0x000000000000000000000000000000000000aaab" { + t.Fatalf("incorrect burnt contract address: expected %s, got %s", "0x000000000000000000000000000000000000aaab", burnContractAddr11) + } + if burnContractAddr99 != "0x000000000000000000000000000000000000aaab" { + t.Fatalf("incorrect burnt contract address: expected %s, got %s", "0x000000000000000000000000000000000000aaab", burnContractAddr99) + } + if burnContractAddr100 != "0x000000000000000000000000000000000000aaad" { + t.Fatalf("incorrect burnt contract address: expected %s, got %s", "0x000000000000000000000000000000000000aaad", burnContractAddr100) + } + if burnContractAddr101 != "0x000000000000000000000000000000000000aaad" { + t.Fatalf("incorrect burnt contract address: expected %s, got %s", "0x000000000000000000000000000000000000aaad", burnContractAddr101) + } + if burnContractAddr999 != "0x000000000000000000000000000000000000aaad" { + t.Fatalf("incorrect burnt contract address: expected %s, got %s", "0x000000000000000000000000000000000000aaad", burnContractAddr999) + } + if burnContractAddr1000 != "0x000000000000000000000000000000000000aaae" { + t.Fatalf("incorrect burnt contract address: expected %s, got %s", "0x000000000000000000000000000000000000aaae", burnContractAddr1000) + } + if burnContractAddr1001 != "0x000000000000000000000000000000000000aaae" { + t.Fatalf("incorrect burnt contract address: expected %s, got %s", "0x000000000000000000000000000000000000aaae", burnContractAddr1001) + } +} + // EIP1559 is not supported without EIP155. An error is expected func TestEIP1559TransitionWithEIP155(t *testing.T) { var ( diff --git a/tests/bor/helper.go b/tests/bor/helper.go index ba9b687d25..dfde4baed8 100644 --- a/tests/bor/helper.go +++ b/tests/bor/helper.go @@ -220,7 +220,11 @@ func buildNextBlock(t *testing.T, _bor consensus.Engine, chain *core.BlockChain, ctx := context.Background() // Finalize and seal the block - block, _ := _bor.FinalizeAndAssemble(ctx, chain, b.header, state, b.txs, nil, b.receipts, []*types.Withdrawal{}) + block, err := _bor.FinalizeAndAssemble(ctx, chain, b.header, state, b.txs, nil, b.receipts, nil) + + if err != nil { + panic(fmt.Sprintf("error finalizing block: %v", err)) + } // Write state changes to db root, err := state.Commit(chain.Config().IsEIP158(b.header.Number)) diff --git a/tests/init.go b/tests/init.go index 13456feb9a..e81c7823b3 100644 --- a/tests/init.go +++ b/tests/init.go @@ -302,7 +302,7 @@ var Forks = map[string]*params.ChainConfig{ ArrowGlacierBlock: big.NewInt(0), MergeNetsplitBlock: big.NewInt(0), TerminalTotalDifficulty: big.NewInt(0), - ShanghaiTime: u64(0), + ShanghaiBlock: big.NewInt(0), Bor: params.BorUnittestChainConfig.Bor, }, "MergeToShanghaiAtTime15k": { @@ -321,7 +321,7 @@ var Forks = map[string]*params.ChainConfig{ ArrowGlacierBlock: big.NewInt(0), MergeNetsplitBlock: big.NewInt(0), TerminalTotalDifficulty: big.NewInt(0), - ShanghaiTime: u64(15_000), + ShanghaiBlock: big.NewInt(0), Bor: params.BorUnittestChainConfig.Bor, }, }