From 0d0707abc72da675c84f8b8a65cc4fe6854d013d Mon Sep 17 00:00:00 2001 From: AnkushinDaniil Date: Tue, 14 Jan 2025 12:42:37 +0300 Subject: [PATCH 01/14] Add bootnode registry abi and generate go files --- l1/abi/bootnode_registry.json | 217 ++++++ l1/contract/bootnode_registry.go | 1089 ++++++++++++++++++++++++++++++ 2 files changed, 1306 insertions(+) create mode 100644 l1/abi/bootnode_registry.json create mode 100644 l1/contract/bootnode_registry.go diff --git a/l1/abi/bootnode_registry.json b/l1/abi/bootnode_registry.json new file mode 100644 index 0000000000..b46d275791 --- /dev/null +++ b/l1/abi/bootnode_registry.json @@ -0,0 +1,217 @@ +[ + { + "inputs": [ + { + "internalType": "address", + "name": "_updater", + "type": "address" + } + ], + "name": "addAuthorizedUpdater", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "_ipAddress", + "type": "string" + } + ], + "name": "addIPAddress", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "OwnableInvalidOwner", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "OwnableUnauthorizedAccount", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string", + "name": "ipAddress", + "type": "string" + } + ], + "name": "IPAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string", + "name": "ipAddress", + "type": "string" + } + ], + "name": "IPRemoved", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_updater", + "type": "address" + } + ], + "name": "removeAuthorizedUpdater", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "removeIPAddress", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "updater", + "type": "address" + } + ], + "name": "UpdaterAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "updater", + "type": "address" + } + ], + "name": "UpdaterRemoved", + "type": "event" + }, + { + "inputs": [], + "name": "getIPAddresses", + "outputs": [ + { + "internalType": "string[]", + "name": "", + "type": "string[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_updater", + "type": "address" + } + ], + "name": "isAuthorizedUpdater", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/l1/contract/bootnode_registry.go b/l1/contract/bootnode_registry.go new file mode 100644 index 0000000000..61368c0c48 --- /dev/null +++ b/l1/contract/bootnode_registry.go @@ -0,0 +1,1089 @@ +// Code generated - DO NOT EDIT. +// This file is a generated binding and any manual changes will be lost. + +package contract + +import ( + "errors" + "math/big" + "strings" + + ethereum "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/event" +) + +// Reference imports to suppress errors if they are not otherwise used. +var ( + _ = errors.New + _ = big.NewInt + _ = strings.NewReader + _ = ethereum.NotFound + _ = bind.Bind + _ = common.Big1 + _ = types.BloomLookup + _ = event.NewSubscription + _ = abi.ConvertType +) + +// BootnodeRegistryMetaData contains all meta data concerning the BootnodeRegistry contract. +var BootnodeRegistryMetaData = &bind.MetaData{ + ABI: "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_updater\",\"type\":\"address\"}],\"name\":\"addAuthorizedUpdater\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"_ipAddress\",\"type\":\"string\"}],\"name\":\"addIPAddress\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"}],\"name\":\"OwnableInvalidOwner\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"OwnableUnauthorizedAccount\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"string\",\"name\":\"ipAddress\",\"type\":\"string\"}],\"name\":\"IPAdded\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"string\",\"name\":\"ipAddress\",\"type\":\"string\"}],\"name\":\"IPRemoved\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_updater\",\"type\":\"address\"}],\"name\":\"removeAuthorizedUpdater\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"removeIPAddress\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"updater\",\"type\":\"address\"}],\"name\":\"UpdaterAdded\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"updater\",\"type\":\"address\"}],\"name\":\"UpdaterRemoved\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"getIPAddresses\",\"outputs\":[{\"internalType\":\"string[]\",\"name\":\"\",\"type\":\"string[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_updater\",\"type\":\"address\"}],\"name\":\"isAuthorizedUpdater\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]", +} + +// BootnodeRegistryABI is the input ABI used to generate the binding from. +// Deprecated: Use BootnodeRegistryMetaData.ABI instead. +var BootnodeRegistryABI = BootnodeRegistryMetaData.ABI + +// BootnodeRegistry is an auto generated Go binding around an Ethereum contract. +type BootnodeRegistry struct { + BootnodeRegistryCaller // Read-only binding to the contract + BootnodeRegistryTransactor // Write-only binding to the contract + BootnodeRegistryFilterer // Log filterer for contract events +} + +// BootnodeRegistryCaller is an auto generated read-only Go binding around an Ethereum contract. +type BootnodeRegistryCaller struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// BootnodeRegistryTransactor is an auto generated write-only Go binding around an Ethereum contract. +type BootnodeRegistryTransactor struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// BootnodeRegistryFilterer is an auto generated log filtering Go binding around an Ethereum contract events. +type BootnodeRegistryFilterer struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// BootnodeRegistrySession is an auto generated Go binding around an Ethereum contract, +// with pre-set call and transact options. +type BootnodeRegistrySession struct { + Contract *BootnodeRegistry // Generic contract binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// BootnodeRegistryCallerSession is an auto generated read-only Go binding around an Ethereum contract, +// with pre-set call options. +type BootnodeRegistryCallerSession struct { + Contract *BootnodeRegistryCaller // Generic contract caller binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session +} + +// BootnodeRegistryTransactorSession is an auto generated write-only Go binding around an Ethereum contract, +// with pre-set transact options. +type BootnodeRegistryTransactorSession struct { + Contract *BootnodeRegistryTransactor // Generic contract transactor binding to set the session for + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// BootnodeRegistryRaw is an auto generated low-level Go binding around an Ethereum contract. +type BootnodeRegistryRaw struct { + Contract *BootnodeRegistry // Generic contract binding to access the raw methods on +} + +// BootnodeRegistryCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. +type BootnodeRegistryCallerRaw struct { + Contract *BootnodeRegistryCaller // Generic read-only contract binding to access the raw methods on +} + +// BootnodeRegistryTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. +type BootnodeRegistryTransactorRaw struct { + Contract *BootnodeRegistryTransactor // Generic write-only contract binding to access the raw methods on +} + +// NewBootnodeRegistry creates a new instance of BootnodeRegistry, bound to a specific deployed contract. +func NewBootnodeRegistry(address common.Address, backend bind.ContractBackend) (*BootnodeRegistry, error) { + contract, err := bindBootnodeRegistry(address, backend, backend, backend) + if err != nil { + return nil, err + } + return &BootnodeRegistry{BootnodeRegistryCaller: BootnodeRegistryCaller{contract: contract}, BootnodeRegistryTransactor: BootnodeRegistryTransactor{contract: contract}, BootnodeRegistryFilterer: BootnodeRegistryFilterer{contract: contract}}, nil +} + +// NewBootnodeRegistryCaller creates a new read-only instance of BootnodeRegistry, bound to a specific deployed contract. +func NewBootnodeRegistryCaller(address common.Address, caller bind.ContractCaller) (*BootnodeRegistryCaller, error) { + contract, err := bindBootnodeRegistry(address, caller, nil, nil) + if err != nil { + return nil, err + } + return &BootnodeRegistryCaller{contract: contract}, nil +} + +// NewBootnodeRegistryTransactor creates a new write-only instance of BootnodeRegistry, bound to a specific deployed contract. +func NewBootnodeRegistryTransactor(address common.Address, transactor bind.ContractTransactor) (*BootnodeRegistryTransactor, error) { + contract, err := bindBootnodeRegistry(address, nil, transactor, nil) + if err != nil { + return nil, err + } + return &BootnodeRegistryTransactor{contract: contract}, nil +} + +// NewBootnodeRegistryFilterer creates a new log filterer instance of BootnodeRegistry, bound to a specific deployed contract. +func NewBootnodeRegistryFilterer(address common.Address, filterer bind.ContractFilterer) (*BootnodeRegistryFilterer, error) { + contract, err := bindBootnodeRegistry(address, nil, nil, filterer) + if err != nil { + return nil, err + } + return &BootnodeRegistryFilterer{contract: contract}, nil +} + +// bindBootnodeRegistry binds a generic wrapper to an already deployed contract. +func bindBootnodeRegistry(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { + parsed, err := BootnodeRegistryMetaData.GetAbi() + if err != nil { + return nil, err + } + return bind.NewBoundContract(address, *parsed, caller, transactor, filterer), nil +} + +// Call invokes the (constant) contract method with params as input values and +// sets the output to result. The result type might be a single field for simple +// returns, a slice of interfaces for anonymous returns and a struct for named +// returns. +func (_BootnodeRegistry *BootnodeRegistryRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error { + return _BootnodeRegistry.Contract.BootnodeRegistryCaller.contract.Call(opts, result, method, params...) +} + +// Transfer initiates a plain transaction to move funds to the contract, calling +// its default method if one is available. +func (_BootnodeRegistry *BootnodeRegistryRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _BootnodeRegistry.Contract.BootnodeRegistryTransactor.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_BootnodeRegistry *BootnodeRegistryRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _BootnodeRegistry.Contract.BootnodeRegistryTransactor.contract.Transact(opts, method, params...) +} + +// Call invokes the (constant) contract method with params as input values and +// sets the output to result. The result type might be a single field for simple +// returns, a slice of interfaces for anonymous returns and a struct for named +// returns. +func (_BootnodeRegistry *BootnodeRegistryCallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error { + return _BootnodeRegistry.Contract.contract.Call(opts, result, method, params...) +} + +// Transfer initiates a plain transaction to move funds to the contract, calling +// its default method if one is available. +func (_BootnodeRegistry *BootnodeRegistryTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + return _BootnodeRegistry.Contract.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_BootnodeRegistry *BootnodeRegistryTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + return _BootnodeRegistry.Contract.contract.Transact(opts, method, params...) +} + +// GetIPAddresses is a free data retrieval call binding the contract method 0xd42c014a. +// +// Solidity: function getIPAddresses() view returns(string[]) +func (_BootnodeRegistry *BootnodeRegistryCaller) GetIPAddresses(opts *bind.CallOpts) ([]string, error) { + var out []interface{} + err := _BootnodeRegistry.contract.Call(opts, &out, "getIPAddresses") + + if err != nil { + return *new([]string), err + } + + out0 := *abi.ConvertType(out[0], new([]string)).(*[]string) + + return out0, err + +} + +// GetIPAddresses is a free data retrieval call binding the contract method 0xd42c014a. +// +// Solidity: function getIPAddresses() view returns(string[]) +func (_BootnodeRegistry *BootnodeRegistrySession) GetIPAddresses() ([]string, error) { + return _BootnodeRegistry.Contract.GetIPAddresses(&_BootnodeRegistry.CallOpts) +} + +// GetIPAddresses is a free data retrieval call binding the contract method 0xd42c014a. +// +// Solidity: function getIPAddresses() view returns(string[]) +func (_BootnodeRegistry *BootnodeRegistryCallerSession) GetIPAddresses() ([]string, error) { + return _BootnodeRegistry.Contract.GetIPAddresses(&_BootnodeRegistry.CallOpts) +} + +// IsAuthorizedUpdater is a free data retrieval call binding the contract method 0xb865bccc. +// +// Solidity: function isAuthorizedUpdater(address _updater) view returns(bool) +func (_BootnodeRegistry *BootnodeRegistryCaller) IsAuthorizedUpdater(opts *bind.CallOpts, _updater common.Address) (bool, error) { + var out []interface{} + err := _BootnodeRegistry.contract.Call(opts, &out, "isAuthorizedUpdater", _updater) + + if err != nil { + return *new(bool), err + } + + out0 := *abi.ConvertType(out[0], new(bool)).(*bool) + + return out0, err + +} + +// IsAuthorizedUpdater is a free data retrieval call binding the contract method 0xb865bccc. +// +// Solidity: function isAuthorizedUpdater(address _updater) view returns(bool) +func (_BootnodeRegistry *BootnodeRegistrySession) IsAuthorizedUpdater(_updater common.Address) (bool, error) { + return _BootnodeRegistry.Contract.IsAuthorizedUpdater(&_BootnodeRegistry.CallOpts, _updater) +} + +// IsAuthorizedUpdater is a free data retrieval call binding the contract method 0xb865bccc. +// +// Solidity: function isAuthorizedUpdater(address _updater) view returns(bool) +func (_BootnodeRegistry *BootnodeRegistryCallerSession) IsAuthorizedUpdater(_updater common.Address) (bool, error) { + return _BootnodeRegistry.Contract.IsAuthorizedUpdater(&_BootnodeRegistry.CallOpts, _updater) +} + +// Owner is a free data retrieval call binding the contract method 0x8da5cb5b. +// +// Solidity: function owner() view returns(address) +func (_BootnodeRegistry *BootnodeRegistryCaller) Owner(opts *bind.CallOpts) (common.Address, error) { + var out []interface{} + err := _BootnodeRegistry.contract.Call(opts, &out, "owner") + + if err != nil { + return *new(common.Address), err + } + + out0 := *abi.ConvertType(out[0], new(common.Address)).(*common.Address) + + return out0, err + +} + +// Owner is a free data retrieval call binding the contract method 0x8da5cb5b. +// +// Solidity: function owner() view returns(address) +func (_BootnodeRegistry *BootnodeRegistrySession) Owner() (common.Address, error) { + return _BootnodeRegistry.Contract.Owner(&_BootnodeRegistry.CallOpts) +} + +// Owner is a free data retrieval call binding the contract method 0x8da5cb5b. +// +// Solidity: function owner() view returns(address) +func (_BootnodeRegistry *BootnodeRegistryCallerSession) Owner() (common.Address, error) { + return _BootnodeRegistry.Contract.Owner(&_BootnodeRegistry.CallOpts) +} + +// AddAuthorizedUpdater is a paid mutator transaction binding the contract method 0x8c9b9fdc. +// +// Solidity: function addAuthorizedUpdater(address _updater) returns() +func (_BootnodeRegistry *BootnodeRegistryTransactor) AddAuthorizedUpdater(opts *bind.TransactOpts, _updater common.Address) (*types.Transaction, error) { + return _BootnodeRegistry.contract.Transact(opts, "addAuthorizedUpdater", _updater) +} + +// AddAuthorizedUpdater is a paid mutator transaction binding the contract method 0x8c9b9fdc. +// +// Solidity: function addAuthorizedUpdater(address _updater) returns() +func (_BootnodeRegistry *BootnodeRegistrySession) AddAuthorizedUpdater(_updater common.Address) (*types.Transaction, error) { + return _BootnodeRegistry.Contract.AddAuthorizedUpdater(&_BootnodeRegistry.TransactOpts, _updater) +} + +// AddAuthorizedUpdater is a paid mutator transaction binding the contract method 0x8c9b9fdc. +// +// Solidity: function addAuthorizedUpdater(address _updater) returns() +func (_BootnodeRegistry *BootnodeRegistryTransactorSession) AddAuthorizedUpdater(_updater common.Address) (*types.Transaction, error) { + return _BootnodeRegistry.Contract.AddAuthorizedUpdater(&_BootnodeRegistry.TransactOpts, _updater) +} + +// AddIPAddress is a paid mutator transaction binding the contract method 0x90139fa0. +// +// Solidity: function addIPAddress(string _ipAddress) returns() +func (_BootnodeRegistry *BootnodeRegistryTransactor) AddIPAddress(opts *bind.TransactOpts, _ipAddress string) (*types.Transaction, error) { + return _BootnodeRegistry.contract.Transact(opts, "addIPAddress", _ipAddress) +} + +// AddIPAddress is a paid mutator transaction binding the contract method 0x90139fa0. +// +// Solidity: function addIPAddress(string _ipAddress) returns() +func (_BootnodeRegistry *BootnodeRegistrySession) AddIPAddress(_ipAddress string) (*types.Transaction, error) { + return _BootnodeRegistry.Contract.AddIPAddress(&_BootnodeRegistry.TransactOpts, _ipAddress) +} + +// AddIPAddress is a paid mutator transaction binding the contract method 0x90139fa0. +// +// Solidity: function addIPAddress(string _ipAddress) returns() +func (_BootnodeRegistry *BootnodeRegistryTransactorSession) AddIPAddress(_ipAddress string) (*types.Transaction, error) { + return _BootnodeRegistry.Contract.AddIPAddress(&_BootnodeRegistry.TransactOpts, _ipAddress) +} + +// RemoveAuthorizedUpdater is a paid mutator transaction binding the contract method 0x603cda09. +// +// Solidity: function removeAuthorizedUpdater(address _updater) returns() +func (_BootnodeRegistry *BootnodeRegistryTransactor) RemoveAuthorizedUpdater(opts *bind.TransactOpts, _updater common.Address) (*types.Transaction, error) { + return _BootnodeRegistry.contract.Transact(opts, "removeAuthorizedUpdater", _updater) +} + +// RemoveAuthorizedUpdater is a paid mutator transaction binding the contract method 0x603cda09. +// +// Solidity: function removeAuthorizedUpdater(address _updater) returns() +func (_BootnodeRegistry *BootnodeRegistrySession) RemoveAuthorizedUpdater(_updater common.Address) (*types.Transaction, error) { + return _BootnodeRegistry.Contract.RemoveAuthorizedUpdater(&_BootnodeRegistry.TransactOpts, _updater) +} + +// RemoveAuthorizedUpdater is a paid mutator transaction binding the contract method 0x603cda09. +// +// Solidity: function removeAuthorizedUpdater(address _updater) returns() +func (_BootnodeRegistry *BootnodeRegistryTransactorSession) RemoveAuthorizedUpdater(_updater common.Address) (*types.Transaction, error) { + return _BootnodeRegistry.Contract.RemoveAuthorizedUpdater(&_BootnodeRegistry.TransactOpts, _updater) +} + +// RemoveIPAddress is a paid mutator transaction binding the contract method 0xba14bc71. +// +// Solidity: function removeIPAddress(uint256 index) returns() +func (_BootnodeRegistry *BootnodeRegistryTransactor) RemoveIPAddress(opts *bind.TransactOpts, index *big.Int) (*types.Transaction, error) { + return _BootnodeRegistry.contract.Transact(opts, "removeIPAddress", index) +} + +// RemoveIPAddress is a paid mutator transaction binding the contract method 0xba14bc71. +// +// Solidity: function removeIPAddress(uint256 index) returns() +func (_BootnodeRegistry *BootnodeRegistrySession) RemoveIPAddress(index *big.Int) (*types.Transaction, error) { + return _BootnodeRegistry.Contract.RemoveIPAddress(&_BootnodeRegistry.TransactOpts, index) +} + +// RemoveIPAddress is a paid mutator transaction binding the contract method 0xba14bc71. +// +// Solidity: function removeIPAddress(uint256 index) returns() +func (_BootnodeRegistry *BootnodeRegistryTransactorSession) RemoveIPAddress(index *big.Int) (*types.Transaction, error) { + return _BootnodeRegistry.Contract.RemoveIPAddress(&_BootnodeRegistry.TransactOpts, index) +} + +// RenounceOwnership is a paid mutator transaction binding the contract method 0x715018a6. +// +// Solidity: function renounceOwnership() returns() +func (_BootnodeRegistry *BootnodeRegistryTransactor) RenounceOwnership(opts *bind.TransactOpts) (*types.Transaction, error) { + return _BootnodeRegistry.contract.Transact(opts, "renounceOwnership") +} + +// RenounceOwnership is a paid mutator transaction binding the contract method 0x715018a6. +// +// Solidity: function renounceOwnership() returns() +func (_BootnodeRegistry *BootnodeRegistrySession) RenounceOwnership() (*types.Transaction, error) { + return _BootnodeRegistry.Contract.RenounceOwnership(&_BootnodeRegistry.TransactOpts) +} + +// RenounceOwnership is a paid mutator transaction binding the contract method 0x715018a6. +// +// Solidity: function renounceOwnership() returns() +func (_BootnodeRegistry *BootnodeRegistryTransactorSession) RenounceOwnership() (*types.Transaction, error) { + return _BootnodeRegistry.Contract.RenounceOwnership(&_BootnodeRegistry.TransactOpts) +} + +// TransferOwnership is a paid mutator transaction binding the contract method 0xf2fde38b. +// +// Solidity: function transferOwnership(address newOwner) returns() +func (_BootnodeRegistry *BootnodeRegistryTransactor) TransferOwnership(opts *bind.TransactOpts, newOwner common.Address) (*types.Transaction, error) { + return _BootnodeRegistry.contract.Transact(opts, "transferOwnership", newOwner) +} + +// TransferOwnership is a paid mutator transaction binding the contract method 0xf2fde38b. +// +// Solidity: function transferOwnership(address newOwner) returns() +func (_BootnodeRegistry *BootnodeRegistrySession) TransferOwnership(newOwner common.Address) (*types.Transaction, error) { + return _BootnodeRegistry.Contract.TransferOwnership(&_BootnodeRegistry.TransactOpts, newOwner) +} + +// TransferOwnership is a paid mutator transaction binding the contract method 0xf2fde38b. +// +// Solidity: function transferOwnership(address newOwner) returns() +func (_BootnodeRegistry *BootnodeRegistryTransactorSession) TransferOwnership(newOwner common.Address) (*types.Transaction, error) { + return _BootnodeRegistry.Contract.TransferOwnership(&_BootnodeRegistry.TransactOpts, newOwner) +} + +// BootnodeRegistryIPAddedIterator is returned from FilterIPAdded and is used to iterate over the raw logs and unpacked data for IPAdded events raised by the BootnodeRegistry contract. +type BootnodeRegistryIPAddedIterator struct { + Event *BootnodeRegistryIPAdded // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *BootnodeRegistryIPAddedIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(BootnodeRegistryIPAdded) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(BootnodeRegistryIPAdded) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *BootnodeRegistryIPAddedIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *BootnodeRegistryIPAddedIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// BootnodeRegistryIPAdded represents a IPAdded event raised by the BootnodeRegistry contract. +type BootnodeRegistryIPAdded struct { + IpAddress string + Raw types.Log // Blockchain specific contextual infos +} + +// FilterIPAdded is a free log retrieval operation binding the contract event 0xe7f7a48f1891a089b5b0418c215a3fdc894029f208c5b5930473161f39ae988b. +// +// Solidity: event IPAdded(string ipAddress) +func (_BootnodeRegistry *BootnodeRegistryFilterer) FilterIPAdded(opts *bind.FilterOpts) (*BootnodeRegistryIPAddedIterator, error) { + + logs, sub, err := _BootnodeRegistry.contract.FilterLogs(opts, "IPAdded") + if err != nil { + return nil, err + } + return &BootnodeRegistryIPAddedIterator{contract: _BootnodeRegistry.contract, event: "IPAdded", logs: logs, sub: sub}, nil +} + +// WatchIPAdded is a free log subscription operation binding the contract event 0xe7f7a48f1891a089b5b0418c215a3fdc894029f208c5b5930473161f39ae988b. +// +// Solidity: event IPAdded(string ipAddress) +func (_BootnodeRegistry *BootnodeRegistryFilterer) WatchIPAdded(opts *bind.WatchOpts, sink chan<- *BootnodeRegistryIPAdded) (event.Subscription, error) { + + logs, sub, err := _BootnodeRegistry.contract.WatchLogs(opts, "IPAdded") + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(BootnodeRegistryIPAdded) + if err := _BootnodeRegistry.contract.UnpackLog(event, "IPAdded", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseIPAdded is a log parse operation binding the contract event 0xe7f7a48f1891a089b5b0418c215a3fdc894029f208c5b5930473161f39ae988b. +// +// Solidity: event IPAdded(string ipAddress) +func (_BootnodeRegistry *BootnodeRegistryFilterer) ParseIPAdded(log types.Log) (*BootnodeRegistryIPAdded, error) { + event := new(BootnodeRegistryIPAdded) + if err := _BootnodeRegistry.contract.UnpackLog(event, "IPAdded", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} + +// BootnodeRegistryIPRemovedIterator is returned from FilterIPRemoved and is used to iterate over the raw logs and unpacked data for IPRemoved events raised by the BootnodeRegistry contract. +type BootnodeRegistryIPRemovedIterator struct { + Event *BootnodeRegistryIPRemoved // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *BootnodeRegistryIPRemovedIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(BootnodeRegistryIPRemoved) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(BootnodeRegistryIPRemoved) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *BootnodeRegistryIPRemovedIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *BootnodeRegistryIPRemovedIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// BootnodeRegistryIPRemoved represents a IPRemoved event raised by the BootnodeRegistry contract. +type BootnodeRegistryIPRemoved struct { + IpAddress string + Raw types.Log // Blockchain specific contextual infos +} + +// FilterIPRemoved is a free log retrieval operation binding the contract event 0x45fe66c64cad3093171b605f5ffe092b5333c407560ee34f49a9096c6b312c4f. +// +// Solidity: event IPRemoved(string ipAddress) +func (_BootnodeRegistry *BootnodeRegistryFilterer) FilterIPRemoved(opts *bind.FilterOpts) (*BootnodeRegistryIPRemovedIterator, error) { + + logs, sub, err := _BootnodeRegistry.contract.FilterLogs(opts, "IPRemoved") + if err != nil { + return nil, err + } + return &BootnodeRegistryIPRemovedIterator{contract: _BootnodeRegistry.contract, event: "IPRemoved", logs: logs, sub: sub}, nil +} + +// WatchIPRemoved is a free log subscription operation binding the contract event 0x45fe66c64cad3093171b605f5ffe092b5333c407560ee34f49a9096c6b312c4f. +// +// Solidity: event IPRemoved(string ipAddress) +func (_BootnodeRegistry *BootnodeRegistryFilterer) WatchIPRemoved(opts *bind.WatchOpts, sink chan<- *BootnodeRegistryIPRemoved) (event.Subscription, error) { + + logs, sub, err := _BootnodeRegistry.contract.WatchLogs(opts, "IPRemoved") + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(BootnodeRegistryIPRemoved) + if err := _BootnodeRegistry.contract.UnpackLog(event, "IPRemoved", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseIPRemoved is a log parse operation binding the contract event 0x45fe66c64cad3093171b605f5ffe092b5333c407560ee34f49a9096c6b312c4f. +// +// Solidity: event IPRemoved(string ipAddress) +func (_BootnodeRegistry *BootnodeRegistryFilterer) ParseIPRemoved(log types.Log) (*BootnodeRegistryIPRemoved, error) { + event := new(BootnodeRegistryIPRemoved) + if err := _BootnodeRegistry.contract.UnpackLog(event, "IPRemoved", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} + +// BootnodeRegistryOwnershipTransferredIterator is returned from FilterOwnershipTransferred and is used to iterate over the raw logs and unpacked data for OwnershipTransferred events raised by the BootnodeRegistry contract. +type BootnodeRegistryOwnershipTransferredIterator struct { + Event *BootnodeRegistryOwnershipTransferred // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *BootnodeRegistryOwnershipTransferredIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(BootnodeRegistryOwnershipTransferred) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(BootnodeRegistryOwnershipTransferred) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *BootnodeRegistryOwnershipTransferredIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *BootnodeRegistryOwnershipTransferredIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// BootnodeRegistryOwnershipTransferred represents a OwnershipTransferred event raised by the BootnodeRegistry contract. +type BootnodeRegistryOwnershipTransferred struct { + PreviousOwner common.Address + NewOwner common.Address + Raw types.Log // Blockchain specific contextual infos +} + +// FilterOwnershipTransferred is a free log retrieval operation binding the contract event 0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0. +// +// Solidity: event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) +func (_BootnodeRegistry *BootnodeRegistryFilterer) FilterOwnershipTransferred(opts *bind.FilterOpts, previousOwner []common.Address, newOwner []common.Address) (*BootnodeRegistryOwnershipTransferredIterator, error) { + + var previousOwnerRule []interface{} + for _, previousOwnerItem := range previousOwner { + previousOwnerRule = append(previousOwnerRule, previousOwnerItem) + } + var newOwnerRule []interface{} + for _, newOwnerItem := range newOwner { + newOwnerRule = append(newOwnerRule, newOwnerItem) + } + + logs, sub, err := _BootnodeRegistry.contract.FilterLogs(opts, "OwnershipTransferred", previousOwnerRule, newOwnerRule) + if err != nil { + return nil, err + } + return &BootnodeRegistryOwnershipTransferredIterator{contract: _BootnodeRegistry.contract, event: "OwnershipTransferred", logs: logs, sub: sub}, nil +} + +// WatchOwnershipTransferred is a free log subscription operation binding the contract event 0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0. +// +// Solidity: event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) +func (_BootnodeRegistry *BootnodeRegistryFilterer) WatchOwnershipTransferred(opts *bind.WatchOpts, sink chan<- *BootnodeRegistryOwnershipTransferred, previousOwner []common.Address, newOwner []common.Address) (event.Subscription, error) { + + var previousOwnerRule []interface{} + for _, previousOwnerItem := range previousOwner { + previousOwnerRule = append(previousOwnerRule, previousOwnerItem) + } + var newOwnerRule []interface{} + for _, newOwnerItem := range newOwner { + newOwnerRule = append(newOwnerRule, newOwnerItem) + } + + logs, sub, err := _BootnodeRegistry.contract.WatchLogs(opts, "OwnershipTransferred", previousOwnerRule, newOwnerRule) + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(BootnodeRegistryOwnershipTransferred) + if err := _BootnodeRegistry.contract.UnpackLog(event, "OwnershipTransferred", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseOwnershipTransferred is a log parse operation binding the contract event 0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0. +// +// Solidity: event OwnershipTransferred(address indexed previousOwner, address indexed newOwner) +func (_BootnodeRegistry *BootnodeRegistryFilterer) ParseOwnershipTransferred(log types.Log) (*BootnodeRegistryOwnershipTransferred, error) { + event := new(BootnodeRegistryOwnershipTransferred) + if err := _BootnodeRegistry.contract.UnpackLog(event, "OwnershipTransferred", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} + +// BootnodeRegistryUpdaterAddedIterator is returned from FilterUpdaterAdded and is used to iterate over the raw logs and unpacked data for UpdaterAdded events raised by the BootnodeRegistry contract. +type BootnodeRegistryUpdaterAddedIterator struct { + Event *BootnodeRegistryUpdaterAdded // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *BootnodeRegistryUpdaterAddedIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(BootnodeRegistryUpdaterAdded) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(BootnodeRegistryUpdaterAdded) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *BootnodeRegistryUpdaterAddedIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *BootnodeRegistryUpdaterAddedIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// BootnodeRegistryUpdaterAdded represents a UpdaterAdded event raised by the BootnodeRegistry contract. +type BootnodeRegistryUpdaterAdded struct { + Updater common.Address + Raw types.Log // Blockchain specific contextual infos +} + +// FilterUpdaterAdded is a free log retrieval operation binding the contract event 0x23a38f89c31ff6329bf86f3863cfa2ad8fc1462c40dbf907dbbebb8f9cb237ec. +// +// Solidity: event UpdaterAdded(address updater) +func (_BootnodeRegistry *BootnodeRegistryFilterer) FilterUpdaterAdded(opts *bind.FilterOpts) (*BootnodeRegistryUpdaterAddedIterator, error) { + + logs, sub, err := _BootnodeRegistry.contract.FilterLogs(opts, "UpdaterAdded") + if err != nil { + return nil, err + } + return &BootnodeRegistryUpdaterAddedIterator{contract: _BootnodeRegistry.contract, event: "UpdaterAdded", logs: logs, sub: sub}, nil +} + +// WatchUpdaterAdded is a free log subscription operation binding the contract event 0x23a38f89c31ff6329bf86f3863cfa2ad8fc1462c40dbf907dbbebb8f9cb237ec. +// +// Solidity: event UpdaterAdded(address updater) +func (_BootnodeRegistry *BootnodeRegistryFilterer) WatchUpdaterAdded(opts *bind.WatchOpts, sink chan<- *BootnodeRegistryUpdaterAdded) (event.Subscription, error) { + + logs, sub, err := _BootnodeRegistry.contract.WatchLogs(opts, "UpdaterAdded") + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(BootnodeRegistryUpdaterAdded) + if err := _BootnodeRegistry.contract.UnpackLog(event, "UpdaterAdded", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseUpdaterAdded is a log parse operation binding the contract event 0x23a38f89c31ff6329bf86f3863cfa2ad8fc1462c40dbf907dbbebb8f9cb237ec. +// +// Solidity: event UpdaterAdded(address updater) +func (_BootnodeRegistry *BootnodeRegistryFilterer) ParseUpdaterAdded(log types.Log) (*BootnodeRegistryUpdaterAdded, error) { + event := new(BootnodeRegistryUpdaterAdded) + if err := _BootnodeRegistry.contract.UnpackLog(event, "UpdaterAdded", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} + +// BootnodeRegistryUpdaterRemovedIterator is returned from FilterUpdaterRemoved and is used to iterate over the raw logs and unpacked data for UpdaterRemoved events raised by the BootnodeRegistry contract. +type BootnodeRegistryUpdaterRemovedIterator struct { + Event *BootnodeRegistryUpdaterRemoved // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *BootnodeRegistryUpdaterRemovedIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(BootnodeRegistryUpdaterRemoved) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(BootnodeRegistryUpdaterRemoved) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *BootnodeRegistryUpdaterRemovedIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *BootnodeRegistryUpdaterRemovedIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// BootnodeRegistryUpdaterRemoved represents a UpdaterRemoved event raised by the BootnodeRegistry contract. +type BootnodeRegistryUpdaterRemoved struct { + Updater common.Address + Raw types.Log // Blockchain specific contextual infos +} + +// FilterUpdaterRemoved is a free log retrieval operation binding the contract event 0x209d819a9ec655e89f2b2b9d65c8a78879b45a8f20d1941d69c5fe6dc21bcb62. +// +// Solidity: event UpdaterRemoved(address updater) +func (_BootnodeRegistry *BootnodeRegistryFilterer) FilterUpdaterRemoved(opts *bind.FilterOpts) (*BootnodeRegistryUpdaterRemovedIterator, error) { + + logs, sub, err := _BootnodeRegistry.contract.FilterLogs(opts, "UpdaterRemoved") + if err != nil { + return nil, err + } + return &BootnodeRegistryUpdaterRemovedIterator{contract: _BootnodeRegistry.contract, event: "UpdaterRemoved", logs: logs, sub: sub}, nil +} + +// WatchUpdaterRemoved is a free log subscription operation binding the contract event 0x209d819a9ec655e89f2b2b9d65c8a78879b45a8f20d1941d69c5fe6dc21bcb62. +// +// Solidity: event UpdaterRemoved(address updater) +func (_BootnodeRegistry *BootnodeRegistryFilterer) WatchUpdaterRemoved(opts *bind.WatchOpts, sink chan<- *BootnodeRegistryUpdaterRemoved) (event.Subscription, error) { + + logs, sub, err := _BootnodeRegistry.contract.WatchLogs(opts, "UpdaterRemoved") + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(BootnodeRegistryUpdaterRemoved) + if err := _BootnodeRegistry.contract.UnpackLog(event, "UpdaterRemoved", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseUpdaterRemoved is a log parse operation binding the contract event 0x209d819a9ec655e89f2b2b9d65c8a78879b45a8f20d1941d69c5fe6dc21bcb62. +// +// Solidity: event UpdaterRemoved(address updater) +func (_BootnodeRegistry *BootnodeRegistryFilterer) ParseUpdaterRemoved(log types.Log) (*BootnodeRegistryUpdaterRemoved, error) { + event := new(BootnodeRegistryUpdaterRemoved) + if err := _BootnodeRegistry.contract.UnpackLog(event, "UpdaterRemoved", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} From f0303b514ff2e726bf94dc935661562ab6e28f5f Mon Sep 17 00:00:00 2001 From: AnkushinDaniil Date: Tue, 14 Jan 2025 17:51:16 +0300 Subject: [PATCH 02/14] Add new methods --- l1/eth_subscriber.go | 12 ++++++++++++ l1/l1.go | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/l1/eth_subscriber.go b/l1/eth_subscriber.go index a9490d283e..91ad8f3d3e 100644 --- a/l1/eth_subscriber.go +++ b/l1/eth_subscriber.go @@ -50,6 +50,18 @@ func (s *EthSubscriber) WatchLogStateUpdate(ctx context.Context, sink chan<- *co return s.filterer.WatchLogStateUpdate(&bind.WatchOpts{Context: ctx}, sink) } +func (s *EthSubscriber) WatchIPAdded(ctx context.Context, sink chan<- *contract.BootnodeRegistryIPAdded) (event.Subscription, error) { + return s.bootnodeRegistryFilterer.WatchIPAdded(&bind.WatchOpts{Context: ctx}, sink) +} + +func (s *EthSubscriber) WatchIPRemoved(ctx context.Context, sink chan<- *contract.BootnodeRegistryIPRemoved) (event.Subscription, error) { + return s.bootnodeRegistryFilterer.WatchIPRemoved(&bind.WatchOpts{Context: ctx}, sink) +} + +func (s *EthSubscriber) GetIPAddresses(ctx context.Context, ip common.Address) ([]string, error) { + return s.bootnodeRegistry.GetIPAddresses(&bind.CallOpts{Context: ctx}) +} + func (s *EthSubscriber) ChainID(ctx context.Context) (*big.Int, error) { reqTimer := time.Now() chainID, err := s.ethClient.ChainID(ctx) diff --git a/l1/l1.go b/l1/l1.go index bab31e69e8..59b0a76c77 100644 --- a/l1/l1.go +++ b/l1/l1.go @@ -10,17 +10,22 @@ import ( "github.com/NethermindEth/juno/core" "github.com/NethermindEth/juno/core/felt" "github.com/NethermindEth/juno/l1/contract" + "github.com/NethermindEth/juno/p2p" "github.com/NethermindEth/juno/service" "github.com/NethermindEth/juno/utils" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/event" + "golang.org/x/sync/errgroup" ) //go:generate mockgen -destination=../mocks/mock_subscriber.go -package=mocks github.com/NethermindEth/juno/l1 Subscriber type Subscriber interface { FinalisedHeight(ctx context.Context) (uint64, error) WatchLogStateUpdate(ctx context.Context, sink chan<- *contract.StarknetLogStateUpdate) (event.Subscription, error) + WatchIPAdded(ctx context.Context, sink chan<- *contract.BootnodeRegistryIPAdded) (event.Subscription, error) + WatchIPRemoved(ctx context.Context, sink chan<- *contract.BootnodeRegistryIPRemoved) (event.Subscription, error) + GetIPAddresses(ctx context.Context, ip common.Address) ([]string, error) ChainID(ctx context.Context) (*big.Int, error) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) From 48d26c37e2b2df10b83607d6422eee067eda2fe6 Mon Sep 17 00:00:00 2001 From: AnkushinDaniil Date: Tue, 14 Jan 2025 17:53:19 +0300 Subject: [PATCH 03/14] Add new bootnode registry fields --- l1/eth_subscriber.go | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/l1/eth_subscriber.go b/l1/eth_subscriber.go index 91ad8f3d3e..9b56556990 100644 --- a/l1/eth_subscriber.go +++ b/l1/eth_subscriber.go @@ -8,6 +8,7 @@ import ( "time" "github.com/NethermindEth/juno/l1/contract" + "github.com/NethermindEth/juno/utils" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" @@ -17,15 +18,17 @@ import ( ) type EthSubscriber struct { - ethClient *ethclient.Client - client *rpc.Client - filterer *contract.StarknetFilterer - listener EventListener + ethClient *ethclient.Client + client *rpc.Client + filterer *contract.StarknetFilterer + listener EventListener + bootnodeRegistry *contract.BootnodeRegistry + bootnodeRegistryFilterer *contract.BootnodeRegistryFilterer } var _ Subscriber = (*EthSubscriber)(nil) -func NewEthSubscriber(ethClientAddress string, coreContractAddress common.Address) (*EthSubscriber, error) { +func NewEthSubscriber(ethClientAddress string, network *utils.Network) (*EthSubscriber, error) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() @@ -34,15 +37,34 @@ func NewEthSubscriber(ethClientAddress string, coreContractAddress common.Addres return nil, err } ethClient := ethclient.NewClient(client) - filterer, err := contract.NewStarknetFilterer(coreContractAddress, ethClient) + filterer, err := contract.NewStarknetFilterer(network.CoreContractAddress, ethClient) if err != nil { return nil, err } + + var ( + bootnodeRegistry *contract.BootnodeRegistry + bootnodeRegistryFilterer *contract.BootnodeRegistryFilterer + ) + if network.BootnodeRegistry != emptyBootnodeRegistry { + fmt.Println("Bootnode registry is not empty") + bootnodeRegistry, err = contract.NewBootnodeRegistry(network.BootnodeRegistry, ethClient) + if err != nil { + return nil, err + } + bootnodeRegistryFilterer, err = contract.NewBootnodeRegistryFilterer(network.BootnodeRegistry, ethClient) + if err != nil { + return nil, err + } + } + return &EthSubscriber{ - ethClient: ethClient, - client: client, - filterer: filterer, - listener: SelectiveListener{}, + ethClient: ethClient, + client: client, + filterer: filterer, + listener: SelectiveListener{}, + bootnodeRegistry: bootnodeRegistry, + bootnodeRegistryFilterer: bootnodeRegistryFilterer, }, nil } From 51847fe9054c28d51e47ef71cf07d90bb3a9a456 Mon Sep 17 00:00:00 2001 From: AnkushinDaniil Date: Tue, 14 Jan 2025 18:14:42 +0300 Subject: [PATCH 04/14] Add subscription to new events --- l1/l1.go | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 139 insertions(+), 2 deletions(-) diff --git a/l1/l1.go b/l1/l1.go index 59b0a76c77..2797999dcd 100644 --- a/l1/l1.go +++ b/l1/l1.go @@ -1,3 +1,4 @@ +//go:generate abigen --abi abi/bootnode_registry.json --pkg contract --type BootnodeRegistry --out contract/bootnode_registry.go package l1 import ( @@ -19,6 +20,8 @@ import ( "golang.org/x/sync/errgroup" ) +var emptyBootnodeRegistry = common.Address{} + //go:generate mockgen -destination=../mocks/mock_subscriber.go -package=mocks github.com/NethermindEth/juno/l1 Subscriber type Subscriber interface { FinalisedHeight(ctx context.Context) (uint64, error) @@ -41,11 +44,12 @@ type Client struct { pollFinalisedInterval time.Duration nonFinalisedLogs map[uint64]*contract.StarknetLogStateUpdate listener EventListener + eventsToP2P chan<- p2p.BootnodeRegistryEvent } var _ service.Service = (*Client)(nil) -func NewClient(l1 Subscriber, chain *blockchain.Blockchain, log utils.SimpleLogger) *Client { +func NewClient(l1 Subscriber, chain *blockchain.Blockchain, log utils.SimpleLogger, eventsToP2P chan<- p2p.BootnodeRegistryEvent) *Client { return &Client{ l1: l1, l2Chain: chain, @@ -55,6 +59,7 @@ func NewClient(l1 Subscriber, chain *blockchain.Blockchain, log utils.SimpleLogg pollFinalisedInterval: time.Minute, nonFinalisedLogs: make(map[uint64]*contract.StarknetLogStateUpdate, 0), listener: SelectiveListener{}, + eventsToP2P: eventsToP2P, } } @@ -90,6 +95,42 @@ func (c *Client) subscribeToUpdates(ctx context.Context, updateChan chan *contra } } +func (c *Client) subscribeToBootnodeAddition( + ctx context.Context, updateChan chan *contract.BootnodeRegistryIPAdded, +) (event.Subscription, error) { + for { + select { + case <-ctx.Done(): + return nil, fmt.Errorf("context canceled before resubscribe was successful: %w", ctx.Err()) + default: + updateSub, err := c.l1.WatchIPAdded(ctx, updateChan) + if err == nil { + return updateSub, nil + } + c.log.Debugw("Failed to subscribe to L1 IP address additions", "tryAgainIn", c.resubscribeDelay, "err", err) + time.Sleep(c.resubscribeDelay) + } + } +} + +func (c *Client) subscribeToBootnodeRemoval( + ctx context.Context, updateChan chan *contract.BootnodeRegistryIPRemoved, +) (event.Subscription, error) { + for { + select { + case <-ctx.Done(): + return nil, fmt.Errorf("context canceled before resubscribe was successful: %w", ctx.Err()) + default: + updateSub, err := c.l1.WatchIPRemoved(ctx, updateChan) + if err == nil { + return updateSub, nil + } + c.log.Debugw("Failed to subscribe to L1 IP address removals", "tryAgainIn", c.resubscribeDelay, "err", err) + time.Sleep(c.resubscribeDelay) + } + } +} + func (c *Client) checkChainID(ctx context.Context) error { gotChainID, err := c.l1.ChainID(ctx) if err != nil { @@ -114,8 +155,20 @@ func (c *Client) Run(ctx context.Context) error { buffer := 128 - c.log.Infow("Subscribing to L1 updates...") + errs, ctx := errgroup.WithContext(ctx) + errs.Go(func() error { + return c.makeSubscriptionToStateUpdates(ctx, buffer) + }) + if c.network.BootnodeRegistry != emptyBootnodeRegistry { + errs.Go(func() error { + return c.makeSubscribtionsToBootnodes(ctx, buffer) + }) + } + return errs.Wait() +} +func (c *Client) makeSubscriptionToStateUpdates(ctx context.Context, buffer int) error { + c.log.Infow("Subscribing to L1 updates...") updateChan := make(chan *contract.StarknetLogStateUpdate, buffer) updateSub, err := c.subscribeToUpdates(ctx, updateChan) if err != nil { @@ -127,6 +180,7 @@ func (c *Client) Run(ctx context.Context) error { ticker := time.NewTicker(c.pollFinalisedInterval) defer ticker.Stop() + for { select { case <-ctx.Done(): @@ -175,6 +229,89 @@ func (c *Client) Run(ctx context.Context) error { } } +func (c *Client) makeSubscribtionsToBootnodes(ctx context.Context, buffer int) error { + defer close(c.eventsToP2P) + + addresses, err := c.l1.GetIPAddresses(ctx, c.network.BootnodeRegistry) + if err != nil { + return err + } + + for _, address := range addresses { + select { + case c.eventsToP2P <- p2p.BootnodeRegistryEvent{ + EventType: p2p.Add, + Address: address, + }: + case <-ctx.Done(): + return ctx.Err() + } + } + + addedChan := make(chan *contract.BootnodeRegistryIPAdded, buffer) + addedSub, err := c.subscribeToBootnodeAddition(ctx, addedChan) + if err != nil { + return err + } + defer addedSub.Unsubscribe() + + removedChan := make(chan *contract.BootnodeRegistryIPRemoved, buffer) + removedSub, err := c.subscribeToBootnodeRemoval(ctx, removedChan) + if err != nil { + return err + } + defer removedSub.Unsubscribe() + + c.log.Debugw("Successfully subscribed to bootnode registry events") + + for { + select { + case <-ctx.Done(): + return ctx.Err() + + case err := <-addedSub.Err(): + c.log.Debugw("IP address addition subscription failed, resubscribing", "error", err) + addedSub.Unsubscribe() + + addedSub, err = c.subscribeToBootnodeAddition(ctx, addedChan) + if err != nil { + return err + } + + case err := <-removedSub.Err(): + c.log.Debugw("IP address removal subscription failed, resubscribing", "error", err) + removedSub.Unsubscribe() + + removedSub, err = c.subscribeToBootnodeRemoval(ctx, removedChan) + if err != nil { + return err + } + + case added := <-addedChan: + c.log.Infow("Received bootnode addition", "ip", added.IpAddress) + select { + case c.eventsToP2P <- p2p.BootnodeRegistryEvent{ + EventType: p2p.Add, + Address: added.IpAddress, + }: + case <-ctx.Done(): + return ctx.Err() + } + + case removed := <-removedChan: + c.log.Infow("Received bootnode removal", "ip", removed.IpAddress) + select { + case c.eventsToP2P <- p2p.BootnodeRegistryEvent{ + EventType: p2p.Remove, + Address: removed.IpAddress, + }: + case <-ctx.Done(): + return ctx.Err() + } + } + } +} + func (c *Client) finalisedHeight(ctx context.Context) uint64 { for { select { From edc872d236ed009257c9540c4db14c43c816f390 Mon Sep 17 00:00:00 2001 From: AnkushinDaniil Date: Tue, 14 Jan 2025 18:22:07 +0300 Subject: [PATCH 05/14] Add l1 tests --- l1/l1_pkg_test.go | 205 +++++++++++++++++++++++++++++++++++++++++++++- l1/l1_test.go | 29 ++++++- 2 files changed, 228 insertions(+), 6 deletions(-) diff --git a/l1/l1_pkg_test.go b/l1/l1_pkg_test.go index 4d8f9f0bce..0342576d0e 100644 --- a/l1/l1_pkg_test.go +++ b/l1/l1_pkg_test.go @@ -13,7 +13,9 @@ import ( "github.com/NethermindEth/juno/db/pebble" "github.com/NethermindEth/juno/l1/contract" "github.com/NethermindEth/juno/mocks" + "github.com/NethermindEth/juno/p2p" "github.com/NethermindEth/juno/utils" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -338,7 +340,7 @@ func TestClient(t *testing.T) { network := utils.Mainnet chain := blockchain.New(pebble.NewMemTest(t), &network, nil) - client := NewClient(nil, chain, nopLog).WithResubscribeDelay(0).WithPollFinalisedInterval(time.Nanosecond) + client := NewClient(nil, chain, nopLog, nil).WithResubscribeDelay(0).WithPollFinalisedInterval(time.Nanosecond) // We loop over each block and check that the state agrees with our expectations. for _, block := range tt.blocks { @@ -398,7 +400,7 @@ func TestUnreliableSubscription(t *testing.T) { nopLog := utils.NewNopZapLogger() network := utils.Mainnet chain := blockchain.New(pebble.NewMemTest(t), &network, nil) - client := NewClient(nil, chain, nopLog).WithResubscribeDelay(0).WithPollFinalisedInterval(time.Nanosecond) + client := NewClient(nil, chain, nopLog, nil).WithResubscribeDelay(0).WithPollFinalisedInterval(time.Nanosecond) err := errors.New("test err") for _, block := range longSequenceOfBlocks { @@ -466,3 +468,202 @@ func TestUnreliableSubscription(t *testing.T) { } } } + +func TestMakeSubscribtionsToBootnodes(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + nopLog := utils.NewNopZapLogger() + network := utils.Mainnet + address := common.HexToAddress("0x1234") + network.BootnodeRegistry = address + eventsChan := make(chan p2p.BootnodeRegistryEvent, 10) + chain := blockchain.New(pebble.NewMemTest(t), &network, nil) + client := NewClient(nil, chain, nopLog, eventsChan).WithResubscribeDelay(0).WithPollFinalisedInterval(time.Nanosecond) + + ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond) + defer cancel() + + storedAddresses := []string{"0x1", "0x2", "0x3"} + addressesToAdd := []string{"0x4", "0x5", "0x6"} + addressToRemove := []string{"0x2", "0x5"} + + subscriber := mocks.NewMockSubscriber(ctrl) + client.l1 = subscriber + + subscriber.EXPECT().GetIPAddresses(gomock.Any(), address).Return(addressesToAdd[:2], nil).Times(1) + subscriber.EXPECT().WatchIPAdded(gomock.Any(), gomock.Any()). + DoAndReturn(func(_ context.Context, sink chan<- *contract.BootnodeRegistryIPAdded) (*fakeSubscription, error) { + go func() { + for _, addr := range addressesToAdd { + sink <- &contract.BootnodeRegistryIPAdded{IpAddress: addr} + } + }() + return newFakeSubscription(), nil + }). + Times(1) + + subscriber.EXPECT().WatchIPRemoved(gomock.Any(), gomock.Any()). + DoAndReturn(func(_ context.Context, sink chan<- *contract.BootnodeRegistryIPRemoved) (*fakeSubscription, error) { + go func() { + for _, addr := range addressToRemove { + sink <- &contract.BootnodeRegistryIPRemoved{IpAddress: addr} + } + }() + return newFakeSubscription(), nil + }). + Times(1) + + require.NoError(t, client.makeSubscribtionsToBootnodes(ctx, 1)) + + expectedAddressesToAdd := make(map[string]struct{}, len(addressesToAdd)+len(storedAddresses)) + for _, addr := range addressesToAdd { + expectedAddressesToAdd[addr] = struct{}{} + } + for _, addr := range storedAddresses { + expectedAddressesToAdd[addr] = struct{}{} + } + expectedAddressesToRemove := make(map[string]struct{}, len(addressToRemove)) + for _, addr := range addressToRemove { + expectedAddressesToRemove[addr] = struct{}{} + } + select { + case event := <-eventsChan: + switch event.EventType { + case p2p.Add: + assert.Contains(t, expectedAddressesToAdd, event.Address) + delete(expectedAddressesToAdd, event.Address) + case p2p.Remove: + assert.Contains(t, expectedAddressesToRemove, event.Address) + delete(expectedAddressesToRemove, event.Address) + } + case <-time.After(100 * time.Millisecond): + t.Fatal("Expected IP address addition event") + } +} + +func TestUnreliableSubscriptionToBootnodes(t *testing.T) { + t.Parallel() + address := common.HexToAddress("0x1234") + network := utils.Mainnet + network.BootnodeRegistry = address + chain := blockchain.New(pebble.NewMemTest(t), &network, nil) + nopLog := utils.NewNopZapLogger() + err := errors.New("test err") + + testCases := []struct { + name string + setupMock func(subscriber *mocks.MockSubscriber) + timeOut time.Duration + expectedErr error + }{ + { + name: "GetIPAddresses error", + setupMock: func(subscriber *mocks.MockSubscriber) { + subscriber.EXPECT().GetIPAddresses(gomock.Any(), address).Return(nil, err).Times(1) + }, + timeOut: 50 * time.Millisecond, + expectedErr: err, + }, + { + name: "WatchIPAdded error", + setupMock: func(subscriber *mocks.MockSubscriber) { + subscriber.EXPECT().GetIPAddresses(gomock.Any(), address).Return(nil, nil).Times(1) + subscriber.EXPECT().WatchIPAdded(gomock.Any(), gomock.Any()).Return(nil, err).Times(1) + subscriber.EXPECT().WatchIPRemoved(gomock.Any(), gomock.Any()).Return(newFakeSubscription(), nil).Times(1) + subscriber.EXPECT().WatchIPAdded(gomock.Any(), gomock.Any()).Return(newFakeSubscription(), nil).Times(1) + }, + timeOut: time.Millisecond, + expectedErr: context.DeadlineExceeded, + }, + { + name: "WatchIPRemoved error", + setupMock: func(subscriber *mocks.MockSubscriber) { + subscriber.EXPECT().GetIPAddresses(gomock.Any(), address).Return(nil, nil).Times(1) + subscriber.EXPECT().WatchIPAdded(gomock.Any(), gomock.Any()).Return(newFakeSubscription(), nil).Times(1) + subscriber.EXPECT().WatchIPRemoved(gomock.Any(), gomock.Any()).Return(nil, err).Times(1) + subscriber.EXPECT().WatchIPRemoved(gomock.Any(), gomock.Any()).Return(newFakeSubscription(), nil).Times(1) + }, + timeOut: 50 * time.Millisecond, + expectedErr: context.DeadlineExceeded, + }, + { + name: "Addition subscription error", + setupMock: func(subscriber *mocks.MockSubscriber) { + subscriber.EXPECT().GetIPAddresses(gomock.Any(), address).Return(nil, nil).Times(1) + subscriber.EXPECT().WatchIPAdded(gomock.Any(), gomock.Any()).Return(newFakeSubscription(err), nil).Times(1) + subscriber.EXPECT().WatchIPRemoved(gomock.Any(), gomock.Any()).Return(newFakeSubscription(), nil).Times(1) + subscriber.EXPECT().WatchIPAdded(gomock.Any(), gomock.Any()).Return(newFakeSubscription(), nil).Times(1) + }, + timeOut: 50 * time.Millisecond, + expectedErr: context.DeadlineExceeded, + }, + { + name: "Removal subscription error", + setupMock: func(subscriber *mocks.MockSubscriber) { + subscriber.EXPECT().GetIPAddresses(gomock.Any(), address).Return(nil, nil).Times(1) + subscriber.EXPECT().WatchIPAdded(gomock.Any(), gomock.Any()).Return(newFakeSubscription(), nil).Times(1) + subscriber.EXPECT().WatchIPRemoved(gomock.Any(), gomock.Any()).Return(newFakeSubscription(err), nil).Times(1) + subscriber.EXPECT().WatchIPRemoved(gomock.Any(), gomock.Any()).Return(newFakeSubscription(), nil).Times(1) + }, + timeOut: 50 * time.Millisecond, + expectedErr: context.DeadlineExceeded, + }, + { + name: "Addition subscription expires", + setupMock: func(subscriber *mocks.MockSubscriber) { + subscriber.EXPECT().GetIPAddresses(gomock.Any(), address).DoAndReturn( + func(_ context.Context, _ common.Address) ([]string, error) { + time.Sleep(100 * time.Millisecond) + return nil, nil + }, + ).Times(1) + }, + expectedErr: context.DeadlineExceeded, + timeOut: 50 * time.Millisecond, + }, + { + name: "Removal subscription expires", + setupMock: func(subscriber *mocks.MockSubscriber) { + subscriber.EXPECT().GetIPAddresses(gomock.Any(), address).Return(nil, nil).Times(1) + subscriber.EXPECT().WatchIPAdded(gomock.Any(), gomock.Any()).DoAndReturn( + func(_ context.Context, sink chan<- *contract.BootnodeRegistryIPAdded) (*fakeSubscription, error) { + time.Sleep(100 * time.Millisecond) + return newFakeSubscription(), nil + }, + ).Times(1) + }, + timeOut: 50 * time.Millisecond, + expectedErr: context.DeadlineExceeded, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + eventsChan := make(chan p2p.BootnodeRegistryEvent, 10) + client := Client{ + l1: nil, + l2Chain: chain, + log: nopLog, + network: chain.Network(), + resubscribeDelay: 0, + nonFinalisedLogs: make(map[uint64]*contract.StarknetLogStateUpdate, 0), + listener: SelectiveListener{}, + eventsToP2P: eventsChan, + } + + subscriber := mocks.NewMockSubscriber(ctrl) + client.l1 = subscriber + tc.setupMock(subscriber) + + ctx, cancel := context.WithTimeout(context.Background(), tc.timeOut) + defer cancel() + err := client.makeSubscribtionsToBootnodes(ctx, 1) + require.ErrorIs(t, err, tc.expectedErr) + }) + } +} diff --git a/l1/l1_test.go b/l1/l1_test.go index bb14cc711a..3095328195 100644 --- a/l1/l1_test.go +++ b/l1/l1_test.go @@ -16,6 +16,7 @@ import ( "github.com/NethermindEth/juno/l1" "github.com/NethermindEth/juno/l1/contract" "github.com/NethermindEth/juno/mocks" + "github.com/NethermindEth/juno/p2p" "github.com/NethermindEth/juno/utils" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" @@ -72,7 +73,7 @@ func TestFailToCreateSubscription(t *testing.T) { subscriber.EXPECT().Close().Times(1) - client := l1.NewClient(subscriber, chain, nopLog).WithResubscribeDelay(0).WithPollFinalisedInterval(time.Nanosecond) + client := l1.NewClient(subscriber, chain, nopLog, nil).WithResubscribeDelay(0).WithPollFinalisedInterval(time.Nanosecond) ctx, cancel := context.WithTimeout(context.Background(), time.Second) require.ErrorContains(t, client.Run(ctx), "context canceled before resubscribe was successful") @@ -96,7 +97,7 @@ func TestMismatchedChainID(t *testing.T) { Return(new(big.Int), nil). Times(1) - client := l1.NewClient(subscriber, chain, nopLog).WithResubscribeDelay(0).WithPollFinalisedInterval(time.Nanosecond) + client := l1.NewClient(subscriber, chain, nopLog, nil).WithResubscribeDelay(0).WithPollFinalisedInterval(time.Nanosecond) ctx, cancel := context.WithTimeout(context.Background(), time.Second) t.Cleanup(cancel) @@ -110,6 +111,7 @@ func TestEventListener(t *testing.T) { ctrl := gomock.NewController(t) nopLog := utils.NewNopZapLogger() network := utils.Mainnet + network.BootnodeRegistry = common.HexToAddress("0x1234") chain := blockchain.New(pebble.NewMemTest(t), &network, nil) subscriber := mocks.NewMockSubscriber(ctrl) @@ -126,6 +128,24 @@ func TestEventListener(t *testing.T) { Return(newFakeSubscription(), nil). Times(1) + subscriber. + EXPECT(). + GetIPAddresses(gomock.Any(), gomock.Any()). + Return([]string{}, nil). + Times(1) + + subscriber. + EXPECT(). + WatchIPAdded(gomock.Any(), gomock.Any()). + Return(newFakeSubscription(), nil). + Times(1) + + subscriber. + EXPECT(). + WatchIPRemoved(gomock.Any(), gomock.Any()). + Return(newFakeSubscription(), nil). + Times(1) + subscriber. EXPECT(). FinalisedHeight(gomock.Any()). @@ -141,7 +161,7 @@ func TestEventListener(t *testing.T) { subscriber.EXPECT().Close().Times(1) var got *core.L1Head - client := l1.NewClient(subscriber, chain, nopLog). + client := l1.NewClient(subscriber, chain, nopLog, make(chan<- p2p.BootnodeRegistryEvent)). WithResubscribeDelay(0). WithPollFinalisedInterval(time.Nanosecond). WithEventListener(l1.SelectiveListener{ @@ -247,7 +267,8 @@ func TestEthSubscriber_FinalisedHeight(t *testing.T) { server, listener := startServer("127.0.0.1:0", test.service) defer server.Stop() - subscriber, err := l1.NewEthSubscriber("ws://"+listener.Addr().String(), common.Address{}) + subscriber, err := l1.NewEthSubscriber("ws://"+listener.Addr().String(), + &utils.Network{BootnodeRegistry: common.Address{}}) require.NoError(t, err) defer subscriber.Close() From c05018830c502f8444a430cfe1425bcc2b06c11e Mon Sep 17 00:00:00 2001 From: AnkushinDaniil Date: Tue, 14 Jan 2025 18:22:32 +0300 Subject: [PATCH 06/14] Regenerate mocks --- mocks/mock_blockchain.go | 113 +++++++++++++++++----------------- mocks/mock_event_filterer.go | 33 +++++----- mocks/mock_gateway_handler.go | 1 + mocks/mock_plugin.go | 17 ++--- mocks/mock_starknetdata.go | 73 +++++++++++----------- mocks/mock_state.go | 65 +++++++++---------- mocks/mock_subscriber.go | 78 ++++++++++++++++++----- mocks/mock_synchronizer.go | 1 + mocks/mock_vm.go | 17 ++--- 9 files changed, 226 insertions(+), 172 deletions(-) diff --git a/mocks/mock_blockchain.go b/mocks/mock_blockchain.go index a7de660233..f2ea2c4e23 100644 --- a/mocks/mock_blockchain.go +++ b/mocks/mock_blockchain.go @@ -24,6 +24,7 @@ import ( type MockReader struct { ctrl *gomock.Controller recorder *MockReaderMockRecorder + isgomock struct{} } // MockReaderMockRecorder is the mock recorder for MockReader. @@ -44,93 +45,93 @@ func (m *MockReader) EXPECT() *MockReaderMockRecorder { } // BlockByHash mocks base method. -func (m *MockReader) BlockByHash(arg0 *felt.Felt) (*core.Block, error) { +func (m *MockReader) BlockByHash(hash *felt.Felt) (*core.Block, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BlockByHash", arg0) + ret := m.ctrl.Call(m, "BlockByHash", hash) ret0, _ := ret[0].(*core.Block) ret1, _ := ret[1].(error) return ret0, ret1 } // BlockByHash indicates an expected call of BlockByHash. -func (mr *MockReaderMockRecorder) BlockByHash(arg0 any) *gomock.Call { +func (mr *MockReaderMockRecorder) BlockByHash(hash any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockByHash", reflect.TypeOf((*MockReader)(nil).BlockByHash), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockByHash", reflect.TypeOf((*MockReader)(nil).BlockByHash), hash) } // BlockByNumber mocks base method. -func (m *MockReader) BlockByNumber(arg0 uint64) (*core.Block, error) { +func (m *MockReader) BlockByNumber(number uint64) (*core.Block, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BlockByNumber", arg0) + ret := m.ctrl.Call(m, "BlockByNumber", number) ret0, _ := ret[0].(*core.Block) ret1, _ := ret[1].(error) return ret0, ret1 } // BlockByNumber indicates an expected call of BlockByNumber. -func (mr *MockReaderMockRecorder) BlockByNumber(arg0 any) *gomock.Call { +func (mr *MockReaderMockRecorder) BlockByNumber(number any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockByNumber", reflect.TypeOf((*MockReader)(nil).BlockByNumber), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockByNumber", reflect.TypeOf((*MockReader)(nil).BlockByNumber), number) } // BlockCommitmentsByNumber mocks base method. -func (m *MockReader) BlockCommitmentsByNumber(arg0 uint64) (*core.BlockCommitments, error) { +func (m *MockReader) BlockCommitmentsByNumber(blockNumber uint64) (*core.BlockCommitments, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BlockCommitmentsByNumber", arg0) + ret := m.ctrl.Call(m, "BlockCommitmentsByNumber", blockNumber) ret0, _ := ret[0].(*core.BlockCommitments) ret1, _ := ret[1].(error) return ret0, ret1 } // BlockCommitmentsByNumber indicates an expected call of BlockCommitmentsByNumber. -func (mr *MockReaderMockRecorder) BlockCommitmentsByNumber(arg0 any) *gomock.Call { +func (mr *MockReaderMockRecorder) BlockCommitmentsByNumber(blockNumber any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockCommitmentsByNumber", reflect.TypeOf((*MockReader)(nil).BlockCommitmentsByNumber), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockCommitmentsByNumber", reflect.TypeOf((*MockReader)(nil).BlockCommitmentsByNumber), blockNumber) } // BlockHeaderByHash mocks base method. -func (m *MockReader) BlockHeaderByHash(arg0 *felt.Felt) (*core.Header, error) { +func (m *MockReader) BlockHeaderByHash(hash *felt.Felt) (*core.Header, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BlockHeaderByHash", arg0) + ret := m.ctrl.Call(m, "BlockHeaderByHash", hash) ret0, _ := ret[0].(*core.Header) ret1, _ := ret[1].(error) return ret0, ret1 } // BlockHeaderByHash indicates an expected call of BlockHeaderByHash. -func (mr *MockReaderMockRecorder) BlockHeaderByHash(arg0 any) *gomock.Call { +func (mr *MockReaderMockRecorder) BlockHeaderByHash(hash any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockHeaderByHash", reflect.TypeOf((*MockReader)(nil).BlockHeaderByHash), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockHeaderByHash", reflect.TypeOf((*MockReader)(nil).BlockHeaderByHash), hash) } // BlockHeaderByNumber mocks base method. -func (m *MockReader) BlockHeaderByNumber(arg0 uint64) (*core.Header, error) { +func (m *MockReader) BlockHeaderByNumber(number uint64) (*core.Header, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BlockHeaderByNumber", arg0) + ret := m.ctrl.Call(m, "BlockHeaderByNumber", number) ret0, _ := ret[0].(*core.Header) ret1, _ := ret[1].(error) return ret0, ret1 } // BlockHeaderByNumber indicates an expected call of BlockHeaderByNumber. -func (mr *MockReaderMockRecorder) BlockHeaderByNumber(arg0 any) *gomock.Call { +func (mr *MockReaderMockRecorder) BlockHeaderByNumber(number any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockHeaderByNumber", reflect.TypeOf((*MockReader)(nil).BlockHeaderByNumber), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockHeaderByNumber", reflect.TypeOf((*MockReader)(nil).BlockHeaderByNumber), number) } // EventFilter mocks base method. -func (m *MockReader) EventFilter(arg0 *felt.Felt, arg1 [][]felt.Felt) (blockchain.EventFilterer, error) { +func (m *MockReader) EventFilter(from *felt.Felt, keys [][]felt.Felt) (blockchain.EventFilterer, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "EventFilter", arg0, arg1) + ret := m.ctrl.Call(m, "EventFilter", from, keys) ret0, _ := ret[0].(blockchain.EventFilterer) ret1, _ := ret[1].(error) return ret0, ret1 } // EventFilter indicates an expected call of EventFilter. -func (mr *MockReaderMockRecorder) EventFilter(arg0, arg1 any) *gomock.Call { +func (mr *MockReaderMockRecorder) EventFilter(from, keys any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EventFilter", reflect.TypeOf((*MockReader)(nil).EventFilter), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EventFilter", reflect.TypeOf((*MockReader)(nil).EventFilter), from, keys) } // Head mocks base method. @@ -195,18 +196,18 @@ func (mr *MockReaderMockRecorder) Height() *gomock.Call { } // L1HandlerTxnHash mocks base method. -func (m *MockReader) L1HandlerTxnHash(arg0 *common.Hash) (*felt.Felt, error) { +func (m *MockReader) L1HandlerTxnHash(msgHash *common.Hash) (*felt.Felt, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "L1HandlerTxnHash", arg0) + ret := m.ctrl.Call(m, "L1HandlerTxnHash", msgHash) ret0, _ := ret[0].(*felt.Felt) ret1, _ := ret[1].(error) return ret0, ret1 } // L1HandlerTxnHash indicates an expected call of L1HandlerTxnHash. -func (mr *MockReaderMockRecorder) L1HandlerTxnHash(arg0 any) *gomock.Call { +func (mr *MockReaderMockRecorder) L1HandlerTxnHash(msgHash any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "L1HandlerTxnHash", reflect.TypeOf((*MockReader)(nil).L1HandlerTxnHash), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "L1HandlerTxnHash", reflect.TypeOf((*MockReader)(nil).L1HandlerTxnHash), msgHash) } // L1Head mocks base method. @@ -239,9 +240,9 @@ func (mr *MockReaderMockRecorder) Network() *gomock.Call { } // Receipt mocks base method. -func (m *MockReader) Receipt(arg0 *felt.Felt) (*core.TransactionReceipt, *felt.Felt, uint64, error) { +func (m *MockReader) Receipt(hash *felt.Felt) (*core.TransactionReceipt, *felt.Felt, uint64, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Receipt", arg0) + ret := m.ctrl.Call(m, "Receipt", hash) ret0, _ := ret[0].(*core.TransactionReceipt) ret1, _ := ret[1].(*felt.Felt) ret2, _ := ret[2].(uint64) @@ -250,15 +251,15 @@ func (m *MockReader) Receipt(arg0 *felt.Felt) (*core.TransactionReceipt, *felt.F } // Receipt indicates an expected call of Receipt. -func (mr *MockReaderMockRecorder) Receipt(arg0 any) *gomock.Call { +func (mr *MockReaderMockRecorder) Receipt(hash any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Receipt", reflect.TypeOf((*MockReader)(nil).Receipt), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Receipt", reflect.TypeOf((*MockReader)(nil).Receipt), hash) } // StateAtBlockHash mocks base method. -func (m *MockReader) StateAtBlockHash(arg0 *felt.Felt) (core.StateReader, func() error, error) { +func (m *MockReader) StateAtBlockHash(blockHash *felt.Felt) (core.StateReader, func() error, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "StateAtBlockHash", arg0) + ret := m.ctrl.Call(m, "StateAtBlockHash", blockHash) ret0, _ := ret[0].(core.StateReader) ret1, _ := ret[1].(func() error) ret2, _ := ret[2].(error) @@ -266,15 +267,15 @@ func (m *MockReader) StateAtBlockHash(arg0 *felt.Felt) (core.StateReader, func() } // StateAtBlockHash indicates an expected call of StateAtBlockHash. -func (mr *MockReaderMockRecorder) StateAtBlockHash(arg0 any) *gomock.Call { +func (mr *MockReaderMockRecorder) StateAtBlockHash(blockHash any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateAtBlockHash", reflect.TypeOf((*MockReader)(nil).StateAtBlockHash), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateAtBlockHash", reflect.TypeOf((*MockReader)(nil).StateAtBlockHash), blockHash) } // StateAtBlockNumber mocks base method. -func (m *MockReader) StateAtBlockNumber(arg0 uint64) (core.StateReader, func() error, error) { +func (m *MockReader) StateAtBlockNumber(blockNumber uint64) (core.StateReader, func() error, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "StateAtBlockNumber", arg0) + ret := m.ctrl.Call(m, "StateAtBlockNumber", blockNumber) ret0, _ := ret[0].(core.StateReader) ret1, _ := ret[1].(func() error) ret2, _ := ret[2].(error) @@ -282,39 +283,39 @@ func (m *MockReader) StateAtBlockNumber(arg0 uint64) (core.StateReader, func() e } // StateAtBlockNumber indicates an expected call of StateAtBlockNumber. -func (mr *MockReaderMockRecorder) StateAtBlockNumber(arg0 any) *gomock.Call { +func (mr *MockReaderMockRecorder) StateAtBlockNumber(blockNumber any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateAtBlockNumber", reflect.TypeOf((*MockReader)(nil).StateAtBlockNumber), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateAtBlockNumber", reflect.TypeOf((*MockReader)(nil).StateAtBlockNumber), blockNumber) } // StateUpdateByHash mocks base method. -func (m *MockReader) StateUpdateByHash(arg0 *felt.Felt) (*core.StateUpdate, error) { +func (m *MockReader) StateUpdateByHash(hash *felt.Felt) (*core.StateUpdate, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "StateUpdateByHash", arg0) + ret := m.ctrl.Call(m, "StateUpdateByHash", hash) ret0, _ := ret[0].(*core.StateUpdate) ret1, _ := ret[1].(error) return ret0, ret1 } // StateUpdateByHash indicates an expected call of StateUpdateByHash. -func (mr *MockReaderMockRecorder) StateUpdateByHash(arg0 any) *gomock.Call { +func (mr *MockReaderMockRecorder) StateUpdateByHash(hash any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateUpdateByHash", reflect.TypeOf((*MockReader)(nil).StateUpdateByHash), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateUpdateByHash", reflect.TypeOf((*MockReader)(nil).StateUpdateByHash), hash) } // StateUpdateByNumber mocks base method. -func (m *MockReader) StateUpdateByNumber(arg0 uint64) (*core.StateUpdate, error) { +func (m *MockReader) StateUpdateByNumber(number uint64) (*core.StateUpdate, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "StateUpdateByNumber", arg0) + ret := m.ctrl.Call(m, "StateUpdateByNumber", number) ret0, _ := ret[0].(*core.StateUpdate) ret1, _ := ret[1].(error) return ret0, ret1 } // StateUpdateByNumber indicates an expected call of StateUpdateByNumber. -func (mr *MockReaderMockRecorder) StateUpdateByNumber(arg0 any) *gomock.Call { +func (mr *MockReaderMockRecorder) StateUpdateByNumber(number any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateUpdateByNumber", reflect.TypeOf((*MockReader)(nil).StateUpdateByNumber), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateUpdateByNumber", reflect.TypeOf((*MockReader)(nil).StateUpdateByNumber), number) } // SubscribeL1Head mocks base method. @@ -332,31 +333,31 @@ func (mr *MockReaderMockRecorder) SubscribeL1Head() *gomock.Call { } // TransactionByBlockNumberAndIndex mocks base method. -func (m *MockReader) TransactionByBlockNumberAndIndex(arg0, arg1 uint64) (core.Transaction, error) { +func (m *MockReader) TransactionByBlockNumberAndIndex(blockNumber, index uint64) (core.Transaction, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "TransactionByBlockNumberAndIndex", arg0, arg1) + ret := m.ctrl.Call(m, "TransactionByBlockNumberAndIndex", blockNumber, index) ret0, _ := ret[0].(core.Transaction) ret1, _ := ret[1].(error) return ret0, ret1 } // TransactionByBlockNumberAndIndex indicates an expected call of TransactionByBlockNumberAndIndex. -func (mr *MockReaderMockRecorder) TransactionByBlockNumberAndIndex(arg0, arg1 any) *gomock.Call { +func (mr *MockReaderMockRecorder) TransactionByBlockNumberAndIndex(blockNumber, index any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TransactionByBlockNumberAndIndex", reflect.TypeOf((*MockReader)(nil).TransactionByBlockNumberAndIndex), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TransactionByBlockNumberAndIndex", reflect.TypeOf((*MockReader)(nil).TransactionByBlockNumberAndIndex), blockNumber, index) } // TransactionByHash mocks base method. -func (m *MockReader) TransactionByHash(arg0 *felt.Felt) (core.Transaction, error) { +func (m *MockReader) TransactionByHash(hash *felt.Felt) (core.Transaction, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "TransactionByHash", arg0) + ret := m.ctrl.Call(m, "TransactionByHash", hash) ret0, _ := ret[0].(core.Transaction) ret1, _ := ret[1].(error) return ret0, ret1 } // TransactionByHash indicates an expected call of TransactionByHash. -func (mr *MockReaderMockRecorder) TransactionByHash(arg0 any) *gomock.Call { +func (mr *MockReaderMockRecorder) TransactionByHash(hash any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TransactionByHash", reflect.TypeOf((*MockReader)(nil).TransactionByHash), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TransactionByHash", reflect.TypeOf((*MockReader)(nil).TransactionByHash), hash) } diff --git a/mocks/mock_event_filterer.go b/mocks/mock_event_filterer.go index 8c800fc41b..408b36f637 100644 --- a/mocks/mock_event_filterer.go +++ b/mocks/mock_event_filterer.go @@ -21,6 +21,7 @@ import ( type MockEventFilterer struct { ctrl *gomock.Controller recorder *MockEventFiltererMockRecorder + isgomock struct{} } // MockEventFiltererMockRecorder is the mock recorder for MockEventFilterer. @@ -55,9 +56,9 @@ func (mr *MockEventFiltererMockRecorder) Close() *gomock.Call { } // Events mocks base method. -func (m *MockEventFilterer) Events(arg0 *blockchain.ContinuationToken, arg1 uint64) ([]*blockchain.FilteredEvent, *blockchain.ContinuationToken, error) { +func (m *MockEventFilterer) Events(cToken *blockchain.ContinuationToken, chunkSize uint64) ([]*blockchain.FilteredEvent, *blockchain.ContinuationToken, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Events", arg0, arg1) + ret := m.ctrl.Call(m, "Events", cToken, chunkSize) ret0, _ := ret[0].([]*blockchain.FilteredEvent) ret1, _ := ret[1].(*blockchain.ContinuationToken) ret2, _ := ret[2].(error) @@ -65,49 +66,49 @@ func (m *MockEventFilterer) Events(arg0 *blockchain.ContinuationToken, arg1 uint } // Events indicates an expected call of Events. -func (mr *MockEventFiltererMockRecorder) Events(arg0, arg1 any) *gomock.Call { +func (mr *MockEventFiltererMockRecorder) Events(cToken, chunkSize any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Events", reflect.TypeOf((*MockEventFilterer)(nil).Events), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Events", reflect.TypeOf((*MockEventFilterer)(nil).Events), cToken, chunkSize) } // SetRangeEndBlockByHash mocks base method. -func (m *MockEventFilterer) SetRangeEndBlockByHash(arg0 blockchain.EventFilterRange, arg1 *felt.Felt) error { +func (m *MockEventFilterer) SetRangeEndBlockByHash(filterRange blockchain.EventFilterRange, blockHash *felt.Felt) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SetRangeEndBlockByHash", arg0, arg1) + ret := m.ctrl.Call(m, "SetRangeEndBlockByHash", filterRange, blockHash) ret0, _ := ret[0].(error) return ret0 } // SetRangeEndBlockByHash indicates an expected call of SetRangeEndBlockByHash. -func (mr *MockEventFiltererMockRecorder) SetRangeEndBlockByHash(arg0, arg1 any) *gomock.Call { +func (mr *MockEventFiltererMockRecorder) SetRangeEndBlockByHash(filterRange, blockHash any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetRangeEndBlockByHash", reflect.TypeOf((*MockEventFilterer)(nil).SetRangeEndBlockByHash), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetRangeEndBlockByHash", reflect.TypeOf((*MockEventFilterer)(nil).SetRangeEndBlockByHash), filterRange, blockHash) } // SetRangeEndBlockByNumber mocks base method. -func (m *MockEventFilterer) SetRangeEndBlockByNumber(arg0 blockchain.EventFilterRange, arg1 uint64) error { +func (m *MockEventFilterer) SetRangeEndBlockByNumber(filterRange blockchain.EventFilterRange, blockNumber uint64) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SetRangeEndBlockByNumber", arg0, arg1) + ret := m.ctrl.Call(m, "SetRangeEndBlockByNumber", filterRange, blockNumber) ret0, _ := ret[0].(error) return ret0 } // SetRangeEndBlockByNumber indicates an expected call of SetRangeEndBlockByNumber. -func (mr *MockEventFiltererMockRecorder) SetRangeEndBlockByNumber(arg0, arg1 any) *gomock.Call { +func (mr *MockEventFiltererMockRecorder) SetRangeEndBlockByNumber(filterRange, blockNumber any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetRangeEndBlockByNumber", reflect.TypeOf((*MockEventFilterer)(nil).SetRangeEndBlockByNumber), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetRangeEndBlockByNumber", reflect.TypeOf((*MockEventFilterer)(nil).SetRangeEndBlockByNumber), filterRange, blockNumber) } // WithLimit mocks base method. -func (m *MockEventFilterer) WithLimit(arg0 uint) *blockchain.EventFilter { +func (m *MockEventFilterer) WithLimit(limit uint) *blockchain.EventFilter { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "WithLimit", arg0) + ret := m.ctrl.Call(m, "WithLimit", limit) ret0, _ := ret[0].(*blockchain.EventFilter) return ret0 } // WithLimit indicates an expected call of WithLimit. -func (mr *MockEventFiltererMockRecorder) WithLimit(arg0 any) *gomock.Call { +func (mr *MockEventFiltererMockRecorder) WithLimit(limit any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WithLimit", reflect.TypeOf((*MockEventFilterer)(nil).WithLimit), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WithLimit", reflect.TypeOf((*MockEventFilterer)(nil).WithLimit), limit) } diff --git a/mocks/mock_gateway_handler.go b/mocks/mock_gateway_handler.go index f9bbfc50ea..87cc677079 100644 --- a/mocks/mock_gateway_handler.go +++ b/mocks/mock_gateway_handler.go @@ -21,6 +21,7 @@ import ( type MockGateway struct { ctrl *gomock.Controller recorder *MockGatewayMockRecorder + isgomock struct{} } // MockGatewayMockRecorder is the mock recorder for MockGateway. diff --git a/mocks/mock_plugin.go b/mocks/mock_plugin.go index 678b745220..daea272f44 100644 --- a/mocks/mock_plugin.go +++ b/mocks/mock_plugin.go @@ -22,6 +22,7 @@ import ( type MockJunoPlugin struct { ctrl *gomock.Controller recorder *MockJunoPluginMockRecorder + isgomock struct{} } // MockJunoPluginMockRecorder is the mock recorder for MockJunoPlugin. @@ -56,31 +57,31 @@ func (mr *MockJunoPluginMockRecorder) Init() *gomock.Call { } // NewBlock mocks base method. -func (m *MockJunoPlugin) NewBlock(arg0 *core.Block, arg1 *core.StateUpdate, arg2 map[felt.Felt]core.Class) error { +func (m *MockJunoPlugin) NewBlock(block *core.Block, stateUpdate *core.StateUpdate, newClasses map[felt.Felt]core.Class) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "NewBlock", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "NewBlock", block, stateUpdate, newClasses) ret0, _ := ret[0].(error) return ret0 } // NewBlock indicates an expected call of NewBlock. -func (mr *MockJunoPluginMockRecorder) NewBlock(arg0, arg1, arg2 any) *gomock.Call { +func (mr *MockJunoPluginMockRecorder) NewBlock(block, stateUpdate, newClasses any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewBlock", reflect.TypeOf((*MockJunoPlugin)(nil).NewBlock), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewBlock", reflect.TypeOf((*MockJunoPlugin)(nil).NewBlock), block, stateUpdate, newClasses) } // RevertBlock mocks base method. -func (m *MockJunoPlugin) RevertBlock(arg0, arg1 *plugin.BlockAndStateUpdate, arg2 *core.StateDiff) error { +func (m *MockJunoPlugin) RevertBlock(from, to *plugin.BlockAndStateUpdate, reverseStateDiff *core.StateDiff) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RevertBlock", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "RevertBlock", from, to, reverseStateDiff) ret0, _ := ret[0].(error) return ret0 } // RevertBlock indicates an expected call of RevertBlock. -func (mr *MockJunoPluginMockRecorder) RevertBlock(arg0, arg1, arg2 any) *gomock.Call { +func (mr *MockJunoPluginMockRecorder) RevertBlock(from, to, reverseStateDiff any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RevertBlock", reflect.TypeOf((*MockJunoPlugin)(nil).RevertBlock), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RevertBlock", reflect.TypeOf((*MockJunoPlugin)(nil).RevertBlock), from, to, reverseStateDiff) } // Shutdown mocks base method. diff --git a/mocks/mock_starknetdata.go b/mocks/mock_starknetdata.go index e7338dccb7..3fc78e7645 100644 --- a/mocks/mock_starknetdata.go +++ b/mocks/mock_starknetdata.go @@ -22,6 +22,7 @@ import ( type MockStarknetData struct { ctrl *gomock.Controller recorder *MockStarknetDataMockRecorder + isgomock struct{} } // MockStarknetDataMockRecorder is the mock recorder for MockStarknetData. @@ -42,99 +43,99 @@ func (m *MockStarknetData) EXPECT() *MockStarknetDataMockRecorder { } // BlockByNumber mocks base method. -func (m *MockStarknetData) BlockByNumber(arg0 context.Context, arg1 uint64) (*core.Block, error) { +func (m *MockStarknetData) BlockByNumber(ctx context.Context, blockNumber uint64) (*core.Block, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BlockByNumber", arg0, arg1) + ret := m.ctrl.Call(m, "BlockByNumber", ctx, blockNumber) ret0, _ := ret[0].(*core.Block) ret1, _ := ret[1].(error) return ret0, ret1 } // BlockByNumber indicates an expected call of BlockByNumber. -func (mr *MockStarknetDataMockRecorder) BlockByNumber(arg0, arg1 any) *gomock.Call { +func (mr *MockStarknetDataMockRecorder) BlockByNumber(ctx, blockNumber any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockByNumber", reflect.TypeOf((*MockStarknetData)(nil).BlockByNumber), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockByNumber", reflect.TypeOf((*MockStarknetData)(nil).BlockByNumber), ctx, blockNumber) } // BlockLatest mocks base method. -func (m *MockStarknetData) BlockLatest(arg0 context.Context) (*core.Block, error) { +func (m *MockStarknetData) BlockLatest(ctx context.Context) (*core.Block, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BlockLatest", arg0) + ret := m.ctrl.Call(m, "BlockLatest", ctx) ret0, _ := ret[0].(*core.Block) ret1, _ := ret[1].(error) return ret0, ret1 } // BlockLatest indicates an expected call of BlockLatest. -func (mr *MockStarknetDataMockRecorder) BlockLatest(arg0 any) *gomock.Call { +func (mr *MockStarknetDataMockRecorder) BlockLatest(ctx any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockLatest", reflect.TypeOf((*MockStarknetData)(nil).BlockLatest), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockLatest", reflect.TypeOf((*MockStarknetData)(nil).BlockLatest), ctx) } // BlockPending mocks base method. -func (m *MockStarknetData) BlockPending(arg0 context.Context) (*core.Block, error) { +func (m *MockStarknetData) BlockPending(ctx context.Context) (*core.Block, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BlockPending", arg0) + ret := m.ctrl.Call(m, "BlockPending", ctx) ret0, _ := ret[0].(*core.Block) ret1, _ := ret[1].(error) return ret0, ret1 } // BlockPending indicates an expected call of BlockPending. -func (mr *MockStarknetDataMockRecorder) BlockPending(arg0 any) *gomock.Call { +func (mr *MockStarknetDataMockRecorder) BlockPending(ctx any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockPending", reflect.TypeOf((*MockStarknetData)(nil).BlockPending), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockPending", reflect.TypeOf((*MockStarknetData)(nil).BlockPending), ctx) } // Class mocks base method. -func (m *MockStarknetData) Class(arg0 context.Context, arg1 *felt.Felt) (core.Class, error) { +func (m *MockStarknetData) Class(ctx context.Context, classHash *felt.Felt) (core.Class, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Class", arg0, arg1) + ret := m.ctrl.Call(m, "Class", ctx, classHash) ret0, _ := ret[0].(core.Class) ret1, _ := ret[1].(error) return ret0, ret1 } // Class indicates an expected call of Class. -func (mr *MockStarknetDataMockRecorder) Class(arg0, arg1 any) *gomock.Call { +func (mr *MockStarknetDataMockRecorder) Class(ctx, classHash any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Class", reflect.TypeOf((*MockStarknetData)(nil).Class), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Class", reflect.TypeOf((*MockStarknetData)(nil).Class), ctx, classHash) } // StateUpdate mocks base method. -func (m *MockStarknetData) StateUpdate(arg0 context.Context, arg1 uint64) (*core.StateUpdate, error) { +func (m *MockStarknetData) StateUpdate(ctx context.Context, blockNumber uint64) (*core.StateUpdate, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "StateUpdate", arg0, arg1) + ret := m.ctrl.Call(m, "StateUpdate", ctx, blockNumber) ret0, _ := ret[0].(*core.StateUpdate) ret1, _ := ret[1].(error) return ret0, ret1 } // StateUpdate indicates an expected call of StateUpdate. -func (mr *MockStarknetDataMockRecorder) StateUpdate(arg0, arg1 any) *gomock.Call { +func (mr *MockStarknetDataMockRecorder) StateUpdate(ctx, blockNumber any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateUpdate", reflect.TypeOf((*MockStarknetData)(nil).StateUpdate), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateUpdate", reflect.TypeOf((*MockStarknetData)(nil).StateUpdate), ctx, blockNumber) } // StateUpdatePending mocks base method. -func (m *MockStarknetData) StateUpdatePending(arg0 context.Context) (*core.StateUpdate, error) { +func (m *MockStarknetData) StateUpdatePending(ctx context.Context) (*core.StateUpdate, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "StateUpdatePending", arg0) + ret := m.ctrl.Call(m, "StateUpdatePending", ctx) ret0, _ := ret[0].(*core.StateUpdate) ret1, _ := ret[1].(error) return ret0, ret1 } // StateUpdatePending indicates an expected call of StateUpdatePending. -func (mr *MockStarknetDataMockRecorder) StateUpdatePending(arg0 any) *gomock.Call { +func (mr *MockStarknetDataMockRecorder) StateUpdatePending(ctx any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateUpdatePending", reflect.TypeOf((*MockStarknetData)(nil).StateUpdatePending), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateUpdatePending", reflect.TypeOf((*MockStarknetData)(nil).StateUpdatePending), ctx) } // StateUpdatePendingWithBlock mocks base method. -func (m *MockStarknetData) StateUpdatePendingWithBlock(arg0 context.Context) (*core.StateUpdate, *core.Block, error) { +func (m *MockStarknetData) StateUpdatePendingWithBlock(ctx context.Context) (*core.StateUpdate, *core.Block, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "StateUpdatePendingWithBlock", arg0) + ret := m.ctrl.Call(m, "StateUpdatePendingWithBlock", ctx) ret0, _ := ret[0].(*core.StateUpdate) ret1, _ := ret[1].(*core.Block) ret2, _ := ret[2].(error) @@ -142,15 +143,15 @@ func (m *MockStarknetData) StateUpdatePendingWithBlock(arg0 context.Context) (*c } // StateUpdatePendingWithBlock indicates an expected call of StateUpdatePendingWithBlock. -func (mr *MockStarknetDataMockRecorder) StateUpdatePendingWithBlock(arg0 any) *gomock.Call { +func (mr *MockStarknetDataMockRecorder) StateUpdatePendingWithBlock(ctx any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateUpdatePendingWithBlock", reflect.TypeOf((*MockStarknetData)(nil).StateUpdatePendingWithBlock), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateUpdatePendingWithBlock", reflect.TypeOf((*MockStarknetData)(nil).StateUpdatePendingWithBlock), ctx) } // StateUpdateWithBlock mocks base method. -func (m *MockStarknetData) StateUpdateWithBlock(arg0 context.Context, arg1 uint64) (*core.StateUpdate, *core.Block, error) { +func (m *MockStarknetData) StateUpdateWithBlock(ctx context.Context, blockNumber uint64) (*core.StateUpdate, *core.Block, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "StateUpdateWithBlock", arg0, arg1) + ret := m.ctrl.Call(m, "StateUpdateWithBlock", ctx, blockNumber) ret0, _ := ret[0].(*core.StateUpdate) ret1, _ := ret[1].(*core.Block) ret2, _ := ret[2].(error) @@ -158,22 +159,22 @@ func (m *MockStarknetData) StateUpdateWithBlock(arg0 context.Context, arg1 uint6 } // StateUpdateWithBlock indicates an expected call of StateUpdateWithBlock. -func (mr *MockStarknetDataMockRecorder) StateUpdateWithBlock(arg0, arg1 any) *gomock.Call { +func (mr *MockStarknetDataMockRecorder) StateUpdateWithBlock(ctx, blockNumber any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateUpdateWithBlock", reflect.TypeOf((*MockStarknetData)(nil).StateUpdateWithBlock), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateUpdateWithBlock", reflect.TypeOf((*MockStarknetData)(nil).StateUpdateWithBlock), ctx, blockNumber) } // Transaction mocks base method. -func (m *MockStarknetData) Transaction(arg0 context.Context, arg1 *felt.Felt) (core.Transaction, error) { +func (m *MockStarknetData) Transaction(ctx context.Context, transactionHash *felt.Felt) (core.Transaction, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Transaction", arg0, arg1) + ret := m.ctrl.Call(m, "Transaction", ctx, transactionHash) ret0, _ := ret[0].(core.Transaction) ret1, _ := ret[1].(error) return ret0, ret1 } // Transaction indicates an expected call of Transaction. -func (mr *MockStarknetDataMockRecorder) Transaction(arg0, arg1 any) *gomock.Call { +func (mr *MockStarknetDataMockRecorder) Transaction(ctx, transactionHash any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Transaction", reflect.TypeOf((*MockStarknetData)(nil).Transaction), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Transaction", reflect.TypeOf((*MockStarknetData)(nil).Transaction), ctx, transactionHash) } diff --git a/mocks/mock_state.go b/mocks/mock_state.go index 8994085984..00875e241a 100644 --- a/mocks/mock_state.go +++ b/mocks/mock_state.go @@ -21,6 +21,7 @@ import ( type MockStateHistoryReader struct { ctrl *gomock.Controller recorder *MockStateHistoryReaderMockRecorder + isgomock struct{} } // MockStateHistoryReaderMockRecorder is the mock recorder for MockStateHistoryReader. @@ -41,121 +42,121 @@ func (m *MockStateHistoryReader) EXPECT() *MockStateHistoryReaderMockRecorder { } // Class mocks base method. -func (m *MockStateHistoryReader) Class(arg0 *felt.Felt) (*core.DeclaredClass, error) { +func (m *MockStateHistoryReader) Class(classHash *felt.Felt) (*core.DeclaredClass, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Class", arg0) + ret := m.ctrl.Call(m, "Class", classHash) ret0, _ := ret[0].(*core.DeclaredClass) ret1, _ := ret[1].(error) return ret0, ret1 } // Class indicates an expected call of Class. -func (mr *MockStateHistoryReaderMockRecorder) Class(arg0 any) *gomock.Call { +func (mr *MockStateHistoryReaderMockRecorder) Class(classHash any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Class", reflect.TypeOf((*MockStateHistoryReader)(nil).Class), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Class", reflect.TypeOf((*MockStateHistoryReader)(nil).Class), classHash) } // ContractClassHash mocks base method. -func (m *MockStateHistoryReader) ContractClassHash(arg0 *felt.Felt) (*felt.Felt, error) { +func (m *MockStateHistoryReader) ContractClassHash(addr *felt.Felt) (*felt.Felt, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ContractClassHash", arg0) + ret := m.ctrl.Call(m, "ContractClassHash", addr) ret0, _ := ret[0].(*felt.Felt) ret1, _ := ret[1].(error) return ret0, ret1 } // ContractClassHash indicates an expected call of ContractClassHash. -func (mr *MockStateHistoryReaderMockRecorder) ContractClassHash(arg0 any) *gomock.Call { +func (mr *MockStateHistoryReaderMockRecorder) ContractClassHash(addr any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContractClassHash", reflect.TypeOf((*MockStateHistoryReader)(nil).ContractClassHash), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContractClassHash", reflect.TypeOf((*MockStateHistoryReader)(nil).ContractClassHash), addr) } // ContractClassHashAt mocks base method. -func (m *MockStateHistoryReader) ContractClassHashAt(arg0 *felt.Felt, arg1 uint64) (*felt.Felt, error) { +func (m *MockStateHistoryReader) ContractClassHashAt(addr *felt.Felt, blockNumber uint64) (*felt.Felt, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ContractClassHashAt", arg0, arg1) + ret := m.ctrl.Call(m, "ContractClassHashAt", addr, blockNumber) ret0, _ := ret[0].(*felt.Felt) ret1, _ := ret[1].(error) return ret0, ret1 } // ContractClassHashAt indicates an expected call of ContractClassHashAt. -func (mr *MockStateHistoryReaderMockRecorder) ContractClassHashAt(arg0, arg1 any) *gomock.Call { +func (mr *MockStateHistoryReaderMockRecorder) ContractClassHashAt(addr, blockNumber any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContractClassHashAt", reflect.TypeOf((*MockStateHistoryReader)(nil).ContractClassHashAt), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContractClassHashAt", reflect.TypeOf((*MockStateHistoryReader)(nil).ContractClassHashAt), addr, blockNumber) } // ContractIsAlreadyDeployedAt mocks base method. -func (m *MockStateHistoryReader) ContractIsAlreadyDeployedAt(arg0 *felt.Felt, arg1 uint64) (bool, error) { +func (m *MockStateHistoryReader) ContractIsAlreadyDeployedAt(addr *felt.Felt, blockNumber uint64) (bool, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ContractIsAlreadyDeployedAt", arg0, arg1) + ret := m.ctrl.Call(m, "ContractIsAlreadyDeployedAt", addr, blockNumber) ret0, _ := ret[0].(bool) ret1, _ := ret[1].(error) return ret0, ret1 } // ContractIsAlreadyDeployedAt indicates an expected call of ContractIsAlreadyDeployedAt. -func (mr *MockStateHistoryReaderMockRecorder) ContractIsAlreadyDeployedAt(arg0, arg1 any) *gomock.Call { +func (mr *MockStateHistoryReaderMockRecorder) ContractIsAlreadyDeployedAt(addr, blockNumber any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContractIsAlreadyDeployedAt", reflect.TypeOf((*MockStateHistoryReader)(nil).ContractIsAlreadyDeployedAt), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContractIsAlreadyDeployedAt", reflect.TypeOf((*MockStateHistoryReader)(nil).ContractIsAlreadyDeployedAt), addr, blockNumber) } // ContractNonce mocks base method. -func (m *MockStateHistoryReader) ContractNonce(arg0 *felt.Felt) (*felt.Felt, error) { +func (m *MockStateHistoryReader) ContractNonce(addr *felt.Felt) (*felt.Felt, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ContractNonce", arg0) + ret := m.ctrl.Call(m, "ContractNonce", addr) ret0, _ := ret[0].(*felt.Felt) ret1, _ := ret[1].(error) return ret0, ret1 } // ContractNonce indicates an expected call of ContractNonce. -func (mr *MockStateHistoryReaderMockRecorder) ContractNonce(arg0 any) *gomock.Call { +func (mr *MockStateHistoryReaderMockRecorder) ContractNonce(addr any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContractNonce", reflect.TypeOf((*MockStateHistoryReader)(nil).ContractNonce), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContractNonce", reflect.TypeOf((*MockStateHistoryReader)(nil).ContractNonce), addr) } // ContractNonceAt mocks base method. -func (m *MockStateHistoryReader) ContractNonceAt(arg0 *felt.Felt, arg1 uint64) (*felt.Felt, error) { +func (m *MockStateHistoryReader) ContractNonceAt(addr *felt.Felt, blockNumber uint64) (*felt.Felt, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ContractNonceAt", arg0, arg1) + ret := m.ctrl.Call(m, "ContractNonceAt", addr, blockNumber) ret0, _ := ret[0].(*felt.Felt) ret1, _ := ret[1].(error) return ret0, ret1 } // ContractNonceAt indicates an expected call of ContractNonceAt. -func (mr *MockStateHistoryReaderMockRecorder) ContractNonceAt(arg0, arg1 any) *gomock.Call { +func (mr *MockStateHistoryReaderMockRecorder) ContractNonceAt(addr, blockNumber any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContractNonceAt", reflect.TypeOf((*MockStateHistoryReader)(nil).ContractNonceAt), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContractNonceAt", reflect.TypeOf((*MockStateHistoryReader)(nil).ContractNonceAt), addr, blockNumber) } // ContractStorage mocks base method. -func (m *MockStateHistoryReader) ContractStorage(arg0, arg1 *felt.Felt) (*felt.Felt, error) { +func (m *MockStateHistoryReader) ContractStorage(addr, key *felt.Felt) (*felt.Felt, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ContractStorage", arg0, arg1) + ret := m.ctrl.Call(m, "ContractStorage", addr, key) ret0, _ := ret[0].(*felt.Felt) ret1, _ := ret[1].(error) return ret0, ret1 } // ContractStorage indicates an expected call of ContractStorage. -func (mr *MockStateHistoryReaderMockRecorder) ContractStorage(arg0, arg1 any) *gomock.Call { +func (mr *MockStateHistoryReaderMockRecorder) ContractStorage(addr, key any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContractStorage", reflect.TypeOf((*MockStateHistoryReader)(nil).ContractStorage), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContractStorage", reflect.TypeOf((*MockStateHistoryReader)(nil).ContractStorage), addr, key) } // ContractStorageAt mocks base method. -func (m *MockStateHistoryReader) ContractStorageAt(arg0, arg1 *felt.Felt, arg2 uint64) (*felt.Felt, error) { +func (m *MockStateHistoryReader) ContractStorageAt(addr, key *felt.Felt, blockNumber uint64) (*felt.Felt, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ContractStorageAt", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "ContractStorageAt", addr, key, blockNumber) ret0, _ := ret[0].(*felt.Felt) ret1, _ := ret[1].(error) return ret0, ret1 } // ContractStorageAt indicates an expected call of ContractStorageAt. -func (mr *MockStateHistoryReaderMockRecorder) ContractStorageAt(arg0, arg1, arg2 any) *gomock.Call { +func (mr *MockStateHistoryReaderMockRecorder) ContractStorageAt(addr, key, blockNumber any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContractStorageAt", reflect.TypeOf((*MockStateHistoryReader)(nil).ContractStorageAt), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContractStorageAt", reflect.TypeOf((*MockStateHistoryReader)(nil).ContractStorageAt), addr, key, blockNumber) } diff --git a/mocks/mock_subscriber.go b/mocks/mock_subscriber.go index 6babde7d1f..da1b77fc60 100644 --- a/mocks/mock_subscriber.go +++ b/mocks/mock_subscriber.go @@ -25,6 +25,7 @@ import ( type MockSubscriber struct { ctrl *gomock.Controller recorder *MockSubscriberMockRecorder + isgomock struct{} } // MockSubscriberMockRecorder is the mock recorder for MockSubscriber. @@ -45,18 +46,18 @@ func (m *MockSubscriber) EXPECT() *MockSubscriberMockRecorder { } // ChainID mocks base method. -func (m *MockSubscriber) ChainID(arg0 context.Context) (*big.Int, error) { +func (m *MockSubscriber) ChainID(ctx context.Context) (*big.Int, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ChainID", arg0) + ret := m.ctrl.Call(m, "ChainID", ctx) ret0, _ := ret[0].(*big.Int) ret1, _ := ret[1].(error) return ret0, ret1 } // ChainID indicates an expected call of ChainID. -func (mr *MockSubscriberMockRecorder) ChainID(arg0 any) *gomock.Call { +func (mr *MockSubscriberMockRecorder) ChainID(ctx any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChainID", reflect.TypeOf((*MockSubscriber)(nil).ChainID), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChainID", reflect.TypeOf((*MockSubscriber)(nil).ChainID), ctx) } // Close mocks base method. @@ -72,46 +73,91 @@ func (mr *MockSubscriberMockRecorder) Close() *gomock.Call { } // FinalisedHeight mocks base method. -func (m *MockSubscriber) FinalisedHeight(arg0 context.Context) (uint64, error) { +func (m *MockSubscriber) FinalisedHeight(ctx context.Context) (uint64, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "FinalisedHeight", arg0) + ret := m.ctrl.Call(m, "FinalisedHeight", ctx) ret0, _ := ret[0].(uint64) ret1, _ := ret[1].(error) return ret0, ret1 } // FinalisedHeight indicates an expected call of FinalisedHeight. -func (mr *MockSubscriberMockRecorder) FinalisedHeight(arg0 any) *gomock.Call { +func (mr *MockSubscriberMockRecorder) FinalisedHeight(ctx any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FinalisedHeight", reflect.TypeOf((*MockSubscriber)(nil).FinalisedHeight), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FinalisedHeight", reflect.TypeOf((*MockSubscriber)(nil).FinalisedHeight), ctx) +} + +// GetIPAddresses mocks base method. +func (m *MockSubscriber) GetIPAddresses(ctx context.Context, ip common.Address) ([]string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetIPAddresses", ctx, ip) + ret0, _ := ret[0].([]string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetIPAddresses indicates an expected call of GetIPAddresses. +func (mr *MockSubscriberMockRecorder) GetIPAddresses(ctx, ip any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetIPAddresses", reflect.TypeOf((*MockSubscriber)(nil).GetIPAddresses), ctx, ip) } // TransactionReceipt mocks base method. -func (m *MockSubscriber) TransactionReceipt(arg0 context.Context, arg1 common.Hash) (*types.Receipt, error) { +func (m *MockSubscriber) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "TransactionReceipt", arg0, arg1) + ret := m.ctrl.Call(m, "TransactionReceipt", ctx, txHash) ret0, _ := ret[0].(*types.Receipt) ret1, _ := ret[1].(error) return ret0, ret1 } // TransactionReceipt indicates an expected call of TransactionReceipt. -func (mr *MockSubscriberMockRecorder) TransactionReceipt(arg0, arg1 any) *gomock.Call { +func (mr *MockSubscriberMockRecorder) TransactionReceipt(ctx, txHash any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TransactionReceipt", reflect.TypeOf((*MockSubscriber)(nil).TransactionReceipt), ctx, txHash) +} + +// WatchIPAdded mocks base method. +func (m *MockSubscriber) WatchIPAdded(ctx context.Context, sink chan<- *contract.BootnodeRegistryIPAdded) (event.Subscription, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "WatchIPAdded", ctx, sink) + ret0, _ := ret[0].(event.Subscription) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// WatchIPAdded indicates an expected call of WatchIPAdded. +func (mr *MockSubscriberMockRecorder) WatchIPAdded(ctx, sink any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WatchIPAdded", reflect.TypeOf((*MockSubscriber)(nil).WatchIPAdded), ctx, sink) +} + +// WatchIPRemoved mocks base method. +func (m *MockSubscriber) WatchIPRemoved(ctx context.Context, sink chan<- *contract.BootnodeRegistryIPRemoved) (event.Subscription, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "WatchIPRemoved", ctx, sink) + ret0, _ := ret[0].(event.Subscription) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// WatchIPRemoved indicates an expected call of WatchIPRemoved. +func (mr *MockSubscriberMockRecorder) WatchIPRemoved(ctx, sink any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TransactionReceipt", reflect.TypeOf((*MockSubscriber)(nil).TransactionReceipt), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WatchIPRemoved", reflect.TypeOf((*MockSubscriber)(nil).WatchIPRemoved), ctx, sink) } // WatchLogStateUpdate mocks base method. -func (m *MockSubscriber) WatchLogStateUpdate(arg0 context.Context, arg1 chan<- *contract.StarknetLogStateUpdate) (event.Subscription, error) { +func (m *MockSubscriber) WatchLogStateUpdate(ctx context.Context, sink chan<- *contract.StarknetLogStateUpdate) (event.Subscription, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "WatchLogStateUpdate", arg0, arg1) + ret := m.ctrl.Call(m, "WatchLogStateUpdate", ctx, sink) ret0, _ := ret[0].(event.Subscription) ret1, _ := ret[1].(error) return ret0, ret1 } // WatchLogStateUpdate indicates an expected call of WatchLogStateUpdate. -func (mr *MockSubscriberMockRecorder) WatchLogStateUpdate(arg0, arg1 any) *gomock.Call { +func (mr *MockSubscriberMockRecorder) WatchLogStateUpdate(ctx, sink any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WatchLogStateUpdate", reflect.TypeOf((*MockSubscriber)(nil).WatchLogStateUpdate), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WatchLogStateUpdate", reflect.TypeOf((*MockSubscriber)(nil).WatchLogStateUpdate), ctx, sink) } diff --git a/mocks/mock_synchronizer.go b/mocks/mock_synchronizer.go index d04a733db0..f20d0751db 100644 --- a/mocks/mock_synchronizer.go +++ b/mocks/mock_synchronizer.go @@ -21,6 +21,7 @@ import ( type MockSyncReader struct { ctrl *gomock.Controller recorder *MockSyncReaderMockRecorder + isgomock struct{} } // MockSyncReaderMockRecorder is the mock recorder for MockSyncReader. diff --git a/mocks/mock_vm.go b/mocks/mock_vm.go index fce753bd37..3dc7013599 100644 --- a/mocks/mock_vm.go +++ b/mocks/mock_vm.go @@ -23,6 +23,7 @@ import ( type MockVM struct { ctrl *gomock.Controller recorder *MockVMMockRecorder + isgomock struct{} } // MockVMMockRecorder is the mock recorder for MockVM. @@ -43,24 +44,24 @@ func (m *MockVM) EXPECT() *MockVMMockRecorder { } // Call mocks base method. -func (m *MockVM) Call(arg0 *vm.CallInfo, arg1 *vm.BlockInfo, arg2 core.StateReader, arg3 *utils.Network, arg4 uint64) ([]*felt.Felt, error) { +func (m *MockVM) Call(callInfo *vm.CallInfo, blockInfo *vm.BlockInfo, state core.StateReader, network *utils.Network, maxSteps uint64) ([]*felt.Felt, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Call", arg0, arg1, arg2, arg3, arg4) + ret := m.ctrl.Call(m, "Call", callInfo, blockInfo, state, network, maxSteps) ret0, _ := ret[0].([]*felt.Felt) ret1, _ := ret[1].(error) return ret0, ret1 } // Call indicates an expected call of Call. -func (mr *MockVMMockRecorder) Call(arg0, arg1, arg2, arg3, arg4 any) *gomock.Call { +func (mr *MockVMMockRecorder) Call(callInfo, blockInfo, state, network, maxSteps any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Call", reflect.TypeOf((*MockVM)(nil).Call), arg0, arg1, arg2, arg3, arg4) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Call", reflect.TypeOf((*MockVM)(nil).Call), callInfo, blockInfo, state, network, maxSteps) } // Execute mocks base method. -func (m *MockVM) Execute(arg0 []core.Transaction, arg1 []core.Class, arg2 []*felt.Felt, arg3 *vm.BlockInfo, arg4 core.StateReader, arg5 *utils.Network, arg6, arg7, arg8 bool) ([]*felt.Felt, []core.GasConsumed, []vm.TransactionTrace, uint64, error) { +func (m *MockVM) Execute(txns []core.Transaction, declaredClasses []core.Class, paidFeesOnL1 []*felt.Felt, blockInfo *vm.BlockInfo, state core.StateReader, network *utils.Network, skipChargeFee, skipValidate, errOnRevert bool) ([]*felt.Felt, []core.GasConsumed, []vm.TransactionTrace, uint64, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Execute", arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) + ret := m.ctrl.Call(m, "Execute", txns, declaredClasses, paidFeesOnL1, blockInfo, state, network, skipChargeFee, skipValidate, errOnRevert) ret0, _ := ret[0].([]*felt.Felt) ret1, _ := ret[1].([]core.GasConsumed) ret2, _ := ret[2].([]vm.TransactionTrace) @@ -70,7 +71,7 @@ func (m *MockVM) Execute(arg0 []core.Transaction, arg1 []core.Class, arg2 []*fel } // Execute indicates an expected call of Execute. -func (mr *MockVMMockRecorder) Execute(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 any) *gomock.Call { +func (mr *MockVMMockRecorder) Execute(txns, declaredClasses, paidFeesOnL1, blockInfo, state, network, skipChargeFee, skipValidate, errOnRevert any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Execute", reflect.TypeOf((*MockVM)(nil).Execute), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Execute", reflect.TypeOf((*MockVM)(nil).Execute), txns, declaredClasses, paidFeesOnL1, blockInfo, state, network, skipChargeFee, skipValidate, errOnRevert) } From c12fc80e83c7845a84900b39ccb1e904a2410a4e Mon Sep 17 00:00:00 2001 From: AnkushinDaniil Date: Tue, 14 Jan 2025 18:26:24 +0300 Subject: [PATCH 07/14] Add l1 event listener and handler --- p2p/p2p.go | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 3 deletions(-) diff --git a/p2p/p2p.go b/p2p/p2p.go index ddb1ed955d..cf44033682 100644 --- a/p2p/p2p.go +++ b/p2p/p2p.go @@ -35,6 +35,18 @@ const ( clientName = "juno" ) +type BootnodeEvent uint8 + +const ( + Add BootnodeEvent = iota + Remove +) + +type BootnodeRegistryEvent struct { + EventType BootnodeEvent + Address string +} + type Service struct { host host.Host @@ -50,10 +62,12 @@ type Service struct { feederNode bool database db.DB + + l1events <-chan BootnodeRegistryEvent } func New(addr, publicAddr, version, peers, privKeyStr string, feederNode bool, bc *blockchain.Blockchain, snNetwork *utils.Network, - log utils.SimpleLogger, database db.DB, + log utils.SimpleLogger, database db.DB, l1events <-chan BootnodeRegistryEvent, ) (*Service, error) { if addr == "" { // 0.0.0.0/tcp/0 will listen on any interface device and assing a free port. @@ -110,11 +124,11 @@ func New(addr, publicAddr, version, peers, privKeyStr string, feederNode bool, b // Todo: try to understand what will happen if user passes a multiaddr with p2p public and a private key which doesn't match. // For example, a user passes the following multiaddr: --p2p-addr=/ip4/0.0.0.0/tcp/7778/p2p/(SomePublicKey) and also passes a // --p2p-private-key="SomePrivateKey". However, the private public key pair don't match, in this case what will happen? - return NewWithHost(p2pHost, peers, feederNode, bc, snNetwork, log, database) + return NewWithHost(p2pHost, peers, feederNode, bc, snNetwork, log, database, l1events) } func NewWithHost(p2phost host.Host, peers string, feederNode bool, bc *blockchain.Blockchain, snNetwork *utils.Network, - log utils.SimpleLogger, database db.DB, + log utils.SimpleLogger, database db.DB, l1events <-chan BootnodeRegistryEvent, ) (*Service, error) { var ( peersAddrInfoS []peer.AddrInfo @@ -156,6 +170,7 @@ func NewWithHost(p2phost host.Host, peers string, feederNode bool, bc *blockchai feederNode: feederNode, handler: p2pPeers.NewHandler(bc, log), database: database, + l1events: l1events, } return s, nil } @@ -208,6 +223,10 @@ func (s *Service) Run(ctx context.Context) error { } }() + if s.l1events != nil { + go s.listenForL1Events(ctx) + } + err := s.dht.Bootstrap(ctx) if err != nil { return err @@ -249,6 +268,63 @@ func (s *Service) Run(ctx context.Context) error { return nil } +func (s *Service) listenForL1Events(ctx context.Context) { + for { + select { + case <-ctx.Done(): + return + + case registryEvent, ok := <-s.l1events: + if !ok { + s.log.Debugw("L1 events channel closed") + return + } + + peerInfo, err := peer.AddrInfoFromP2pAddr(multiaddr.StringCast(registryEvent.Address)) + if err != nil { + s.log.Warnw("Failed to parse peer address", "peer", registryEvent.Address, "err", err) + continue + } + + switch registryEvent.EventType { + case Add: + if err := s.connectToPeer(ctx, peerInfo, registryEvent.Address); err != nil { + s.log.Warnw("Failed to handle Add event", "peer", registryEvent.Address, "err", err) + } + + case Remove: + if err := s.disconnectFromPeer(peerInfo, registryEvent.Address); err != nil { + s.log.Warnw("Failed to handle Remove event", "peer", registryEvent.Address, "err", err) + } + } + } + } +} + +func (s *Service) connectToPeer(ctx context.Context, peerInfo *peer.AddrInfo, address string) error { + if err := s.host.Connect(ctx, *peerInfo); err != nil { + s.log.Warnw("Failed to connect to peer", "peer", address, "err", err) + return err + } + s.log.Debugw("Connected to peer", "peer", address) + return nil +} + +func (s *Service) disconnectFromPeer(peerInfo *peer.AddrInfo, address string) error { + if err := s.host.Network().ClosePeer(peerInfo.ID); err != nil { + s.log.Warnw("Failed to disconnect from peer", "peer", address, "err", err) + return err + } + + s.log.Debugw("Disconnected from peer", "peer", address) + s.host.Peerstore().RemovePeer(peerInfo.ID) + s.log.Debugw("Removed peer from Peerstore", "peer", peerInfo.ID) + + s.dht.RoutingTable().RemovePeer(peerInfo.ID) + s.log.Debugw("Removed peer from DHT", "peer", peerInfo.ID) + return nil +} + func (s *Service) setProtocolHandlers() { s.SetProtocolHandler(p2pSync.HeadersPID(), s.handler.HeadersHandler) s.SetProtocolHandler(p2pSync.EventsPID(), s.handler.EventsHandler) From ea014c6c91f534bf144a7cf179bb38e7223f25b5 Mon Sep 17 00:00:00 2001 From: AnkushinDaniil Date: Tue, 14 Jan 2025 18:26:45 +0300 Subject: [PATCH 08/14] Add p2p tests --- p2p/p2p_pkg_test.go | 53 +++++++++++++++++++++++++++++++++++++++++++++ p2p/p2p_test.go | 2 ++ 2 files changed, 55 insertions(+) create mode 100644 p2p/p2p_pkg_test.go diff --git a/p2p/p2p_pkg_test.go b/p2p/p2p_pkg_test.go new file mode 100644 index 0000000000..857d2ed1a1 --- /dev/null +++ b/p2p/p2p_pkg_test.go @@ -0,0 +1,53 @@ +package p2p + +import ( + "context" + "testing" + "time" + + "github.com/NethermindEth/juno/db/pebble" + "github.com/NethermindEth/juno/utils" + "github.com/libp2p/go-libp2p/core/peer" + mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" + "github.com/stretchr/testify/require" +) + +func TestListenForL1Events(t *testing.T) { + eventChan := make(chan BootnodeRegistryEvent, 8) + ctx, cancel := context.WithCancel(context.Background()) + defer func() { + cancel() + close(eventChan) + }() + + net, err := mocknet.FullMeshLinked(2) + require.NoError(t, err) + peerHosts := net.Hosts() + require.Len(t, peerHosts, 2) + testDB := pebble.NewMemTest(t) + + peerA, err := NewWithHost(peerHosts[0], "", false, nil, &utils.Integration, utils.NewNopZapLogger(), testDB, eventChan) + require.NoError(t, err) + + go peerA.listenForL1Events(ctx) + + peerB, err := NewWithHost(peerHosts[1], "", false, nil, &utils.Integration, utils.NewNopZapLogger(), testDB, nil) + require.NoError(t, err) + + addr, err := peerB.ListenAddrs() + require.NoError(t, err) + addrStr := addr[0].String() + + eventChan <- BootnodeRegistryEvent{Add, addrStr} + time.Sleep(100 * time.Millisecond) + expectedPeers := map[peer.ID]struct{}{ + peerHosts[0].ID(): {}, + peerHosts[1].ID(): {}, + } + + for _, peer := range peerA.host.Peerstore().Peers() { + require.Contains(t, expectedPeers, peer) + } + + // TODO: test remove event, find a way to remove peer from peerstore +} diff --git a/p2p/p2p_test.go b/p2p/p2p_test.go index 54b19d5900..d5bd377fe1 100644 --- a/p2p/p2p_test.go +++ b/p2p/p2p_test.go @@ -24,6 +24,7 @@ func TestInvalidKey(t *testing.T) { &utils.Integration, utils.NewNopZapLogger(), nil, + nil, ) require.Error(t, err) @@ -61,6 +62,7 @@ func TestLoadAndPersistPeers(t *testing.T) { &utils.Integration, utils.NewNopZapLogger(), testDB, + nil, ) require.NoError(t, err) } From 6d5a98812915790c2a367ea28db67660829acf83 Mon Sep 17 00:00:00 2001 From: AnkushinDaniil Date: Tue, 14 Jan 2025 18:27:44 +0300 Subject: [PATCH 09/14] Add BootnodeRegistry field --- utils/network.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/utils/network.go b/utils/network.go index c0988c82f6..47b9265d50 100644 --- a/utils/network.go +++ b/utils/network.go @@ -22,6 +22,7 @@ type Network struct { L1ChainID *big.Int `json:"l1_chain_id" validate:"required"` L2ChainID string `json:"l2_chain_id" validate:"required"` CoreContractAddress common.Address `json:"core_contract_address" validate:"required"` + BootnodeRegistry common.Address `json:"ip_address_registry"` BlockHashMetaInfo *BlockHashMetaInfo `json:"block_hash_meta_info"` } @@ -107,6 +108,7 @@ var ( First07Block: 0, FallBackSequencerAddress: fallBackSequencerAddress, }, + BootnodeRegistry: common.HexToAddress("0xa2499F2a3Fb071fd99f921038d043eF31B446883"), } SepoliaIntegration = Network{ Name: "sepolia-integration", From 83f6705dc28c0c321bd357413ce73dd9c821d6b0 Mon Sep 17 00:00:00 2001 From: AnkushinDaniil Date: Tue, 14 Jan 2025 18:32:42 +0300 Subject: [PATCH 10/14] Add l1ToP2P channel and change sequence of configs --- node/node.go | 63 ++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/node/node.go b/node/node.go index 586876b4ee..b1c75cbb8e 100644 --- a/node/node.go +++ b/node/node.go @@ -170,6 +170,32 @@ func New(cfg *Config, version string) (*Node, error) { //nolint:gocyclo,funlen services = append(services, plugin.NewService(p)) } + var syncReader sync.Reader = &sync.NoopSynchronizer{} + if synchronizer != nil { + syncReader = synchronizer + } + throttledVM := NewThrottledVM(vm.New(false, log), cfg.MaxVMs, int32(cfg.MaxVMQueue)) + + rpcHandler := rpc.New(chain, syncReader, throttledVM, version, log).WithGateway(gatewayClient).WithFeeder(client) + rpcHandler = rpcHandler.WithFilterLimit(cfg.RPCMaxBlockScan).WithCallMaxSteps(uint64(cfg.RPCCallMaxSteps)) + services = append(services, rpcHandler) + + var l1ToP2P chan p2p.BootnodeRegistryEvent + if !cfg.DisableL1Verification { + // Due to mutually exclusive flag we can do the following. + if cfg.EthNode == "" { + return nil, fmt.Errorf("ethereum node address not found; Use --disable-l1-verification flag if L1 verification is not required") + } + + l1ToP2P = make(chan p2p.BootnodeRegistryEvent) + l1Client, err := newL1Client(cfg.EthNode, cfg.Metrics, chain, log, l1ToP2P) + if err != nil { + return nil, fmt.Errorf("create L1 client: %w", err) + } + services = append(services, l1Client) + rpcHandler.WithL1Client(l1Client.L1()) + } + var p2pService *p2p.Service if cfg.P2P { if cfg.Network == utils.Mainnet { @@ -182,7 +208,7 @@ func New(cfg *Config, version string) (*Node, error) { //nolint:gocyclo,funlen synchronizer = nil } p2pService, err = p2p.New(cfg.P2PAddr, cfg.P2PPublicAddr, version, cfg.P2PPeers, cfg.P2PPrivateKey, cfg.P2PFeederNode, - chain, &cfg.Network, log, database) + chain, &cfg.Network, log, database, l1ToP2P) if err != nil { return nil, fmt.Errorf("set up p2p service: %w", err) } @@ -192,17 +218,6 @@ func New(cfg *Config, version string) (*Node, error) { //nolint:gocyclo,funlen if synchronizer != nil { services = append(services, synchronizer) } - - throttledVM := NewThrottledVM(vm.New(false, log), cfg.MaxVMs, int32(cfg.MaxVMQueue)) - - var syncReader sync.Reader = &sync.NoopSynchronizer{} - if synchronizer != nil { - syncReader = synchronizer - } - - rpcHandler := rpc.New(chain, syncReader, throttledVM, version, log).WithGateway(gatewayClient).WithFeeder(client) - rpcHandler = rpcHandler.WithFilterLimit(cfg.RPCMaxBlockScan).WithCallMaxSteps(uint64(cfg.RPCCallMaxSteps)) - services = append(services, rpcHandler) // to improve RPC throughput we double GOMAXPROCS maxGoroutines := 2 * runtime.GOMAXPROCS(0) jsonrpcServer := jsonrpc.NewServer(maxGoroutines, log).WithValidator(validator.Validator()) @@ -274,21 +289,6 @@ func New(cfg *Config, version string) (*Node, error) { //nolint:gocyclo,funlen metricsService: metricsService, } - if !n.cfg.DisableL1Verification { - // Due to mutually exclusive flag we can do the following. - if n.cfg.EthNode == "" { - return nil, fmt.Errorf("ethereum node address not found; Use --disable-l1-verification flag if L1 verification is not required") - } - - var l1Client *l1.Client - l1Client, err = newL1Client(cfg.EthNode, cfg.Metrics, n.blockchain, n.log) - if err != nil { - return nil, fmt.Errorf("create L1 client: %w", err) - } - n.services = append(n.services, l1Client) - rpcHandler.WithL1Client(l1Client.L1()) - } - if semversion, err := semver.NewVersion(version); err == nil { ug := upgrader.NewUpgrader(semversion, githubAPIUrl, latestReleaseURL, upgraderDelay, n.log) n.services = append(n.services, ug) @@ -299,7 +299,9 @@ func New(cfg *Config, version string) (*Node, error) { //nolint:gocyclo,funlen return n, nil } -func newL1Client(ethNode string, includeMetrics bool, chain *blockchain.Blockchain, log utils.SimpleLogger) (*l1.Client, error) { +func newL1Client(ethNode string, includeMetrics bool, chain *blockchain.Blockchain, + log utils.SimpleLogger, l1ToP2P chan p2p.BootnodeRegistryEvent, +) (*l1.Client, error) { ethNodeURL, err := url.Parse(ethNode) if err != nil { return nil, fmt.Errorf("parse Ethereum node URL: %w", err) @@ -310,13 +312,12 @@ func newL1Client(ethNode string, includeMetrics bool, chain *blockchain.Blockcha network := chain.Network() - var ethSubscriber *l1.EthSubscriber - ethSubscriber, err = l1.NewEthSubscriber(ethNode, network.CoreContractAddress) + ethSubscriber, err := l1.NewEthSubscriber(ethNode, network) if err != nil { return nil, fmt.Errorf("set up ethSubscriber: %w", err) } - l1Client := l1.NewClient(ethSubscriber, chain, log) + l1Client := l1.NewClient(ethSubscriber, chain, log, l1ToP2P) if includeMetrics { l1Client.WithEventListener(makeL1Metrics()) From a66dcb2dfdaae012021e067c7a9a8e977fd4ebb1 Mon Sep 17 00:00:00 2001 From: AnkushinDaniil Date: Tue, 14 Jan 2025 18:32:58 +0300 Subject: [PATCH 11/14] Add node test --- node/node_test.go | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/node/node_test.go b/node/node_test.go index fb3d208593..f48a48cdf8 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -2,6 +2,8 @@ package node_test import ( "context" + "net" + "net/http" "testing" "time" @@ -12,6 +14,7 @@ import ( adaptfeeder "github.com/NethermindEth/juno/starknetdata/feeder" "github.com/NethermindEth/juno/sync" "github.com/NethermindEth/juno/utils" + "github.com/ethereum/go-ethereum/rpc" "github.com/stretchr/testify/require" ) @@ -90,3 +93,59 @@ func TestNetworkVerificationOnNonEmptyDB(t *testing.T) { }) } } + +func TestNodeWithL1Verification(t *testing.T) { + server := rpc.NewServer() + require.NoError(t, server.RegisterName("eth", &testEmptyService{})) + listener, err := net.Listen("tcp", "127.0.0.1:0") + require.NoError(t, err) + go func() { + _ = http.Serve(listener, server.WebsocketHandler([]string{"*"})) + }() + defer server.Stop() + _, err = node.New(&node.Config{ + Network: utils.Network{}, + EthNode: "ws://" + listener.Addr().String(), + DatabasePath: t.TempDir(), + DisableL1Verification: false, + }, "v0.1") + require.NoError(t, err) +} + +func TestNodeWithL1VerificationError(t *testing.T) { + tests := []struct { + name string + cfg *node.Config + err string + }{ + { + name: "no network", + cfg: &node.Config{ + DatabasePath: t.TempDir(), + DisableL1Verification: false, + }, + err: "ethereum node address not found", + }, + { + name: "parce URL error", + cfg: &node.Config{ + DatabasePath: t.TempDir(), + DisableL1Verification: false, + EthNode: string([]byte{0x7f}), + }, + err: "parse Ethereum node URL", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + _, err := node.New(tt.cfg, "v0.1") + require.ErrorContains(t, err, tt.err) + }) + } +} + +type testEmptyService struct{} + +func (testEmptyService) GetBlockByNumber(ctx context.Context, number string, fullTx bool) (interface{}, error) { + return nil, nil +} From 4fd99f4bd5e83b51ccdd91a729e1568f67d5badd Mon Sep 17 00:00:00 2001 From: AnkushinDaniil Date: Tue, 14 Jan 2025 18:37:12 +0300 Subject: [PATCH 12/14] Add l1/internal/contract to codecov --- .github/codecov.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/codecov.yml b/.github/codecov.yml index 8a1bf7a4e9..39daabcee8 100644 --- a/.github/codecov.yml +++ b/.github/codecov.yml @@ -10,11 +10,11 @@ coverage: only_pulls: true ignore: - mocks - - l1/internal/contract/starknet.go + - l1/contract/* - grpc/gen/* - vm - p2p - adapters/core2p2p - adapters/p2p2core - docs - - "**/*_enumer.go" \ No newline at end of file + - "**/*_enumer.go" From 9859227810523541c405f477d3e19edc4954ef3b Mon Sep 17 00:00:00 2001 From: AnkushinDaniil Date: Tue, 14 Jan 2025 18:37:36 +0300 Subject: [PATCH 13/14] Update go.mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 0609e45bfe..3ccc1e279c 100644 --- a/go.mod +++ b/go.mod @@ -33,6 +33,7 @@ require ( go.uber.org/mock v0.5.0 go.uber.org/zap v1.27.0 golang.org/x/crypto v0.32.0 + golang.org/x/sync v0.10.0 google.golang.org/grpc v1.69.4 google.golang.org/protobuf v1.36.1 gopkg.in/yaml.v3 v3.0.1 @@ -190,7 +191,6 @@ require ( golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect golang.org/x/mod v0.21.0 // indirect golang.org/x/net v0.34.0 // indirect - golang.org/x/sync v0.10.0 // indirect golang.org/x/sys v0.29.0 // indirect golang.org/x/text v0.21.0 // indirect golang.org/x/tools v0.26.0 // indirect From 13768ae35e6732926804b484457e71a954336656 Mon Sep 17 00:00:00 2001 From: AnkushinDaniil Date: Tue, 14 Jan 2025 19:34:10 +0300 Subject: [PATCH 14/14] Refactor makeSubscriptionsToBootnodes and fix tests --- l1/l1.go | 50 +++++++++++++++++++++++++++++++---------------- l1/l1_pkg_test.go | 4 ++-- l1/l1_test.go | 2 +- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/l1/l1.go b/l1/l1.go index 2797999dcd..94b2d3d9d9 100644 --- a/l1/l1.go +++ b/l1/l1.go @@ -161,7 +161,7 @@ func (c *Client) Run(ctx context.Context) error { }) if c.network.BootnodeRegistry != emptyBootnodeRegistry { errs.Go(func() error { - return c.makeSubscribtionsToBootnodes(ctx, buffer) + return c.makeSubscriptionsToBootnodes(ctx, buffer) }) } return errs.Wait() @@ -229,41 +229,57 @@ func (c *Client) makeSubscriptionToStateUpdates(ctx context.Context, buffer int) } } -func (c *Client) makeSubscribtionsToBootnodes(ctx context.Context, buffer int) error { +func (c *Client) makeSubscriptionsToBootnodes(ctx context.Context, buffer int) error { defer close(c.eventsToP2P) - addresses, err := c.l1.GetIPAddresses(ctx, c.network.BootnodeRegistry) - if err != nil { + if err := c.processInitialAddresses(ctx); err != nil { return err } - for _, address := range addresses { - select { - case c.eventsToP2P <- p2p.BootnodeRegistryEvent{ - EventType: p2p.Add, - Address: address, - }: - case <-ctx.Done(): - return ctx.Err() - } - } - addedChan := make(chan *contract.BootnodeRegistryIPAdded, buffer) addedSub, err := c.subscribeToBootnodeAddition(ctx, addedChan) if err != nil { - return err + return fmt.Errorf("failed to setup addition subscription: %w", err) } defer addedSub.Unsubscribe() removedChan := make(chan *contract.BootnodeRegistryIPRemoved, buffer) removedSub, err := c.subscribeToBootnodeRemoval(ctx, removedChan) if err != nil { - return err + return fmt.Errorf("failed to setup removal subscription: %w", err) } defer removedSub.Unsubscribe() c.log.Debugw("Successfully subscribed to bootnode registry events") + // Handle events + return c.handleBootnodeEvents(ctx, addedSub, removedSub, addedChan, removedChan) +} + +func (c *Client) processInitialAddresses(ctx context.Context) error { + addresses, err := c.l1.GetIPAddresses(ctx, c.network.BootnodeRegistry) + if err != nil { + return fmt.Errorf("failed to fetch bootnode registry addresses: %w", err) + } + + for _, address := range addresses { + select { + case c.eventsToP2P <- p2p.BootnodeRegistryEvent{ + EventType: p2p.Add, + Address: address, + }: + case <-ctx.Done(): + return ctx.Err() + } + } + return nil +} + +func (c *Client) handleBootnodeEvents( + ctx context.Context, addedSub, removedSub event.Subscription, + addedChan chan *contract.BootnodeRegistryIPAdded, + removedChan chan *contract.BootnodeRegistryIPRemoved, +) error { for { select { case <-ctx.Done(): diff --git a/l1/l1_pkg_test.go b/l1/l1_pkg_test.go index 0342576d0e..8fc3c2bc71 100644 --- a/l1/l1_pkg_test.go +++ b/l1/l1_pkg_test.go @@ -514,7 +514,7 @@ func TestMakeSubscribtionsToBootnodes(t *testing.T) { }). Times(1) - require.NoError(t, client.makeSubscribtionsToBootnodes(ctx, 1)) + require.ErrorIs(t, client.makeSubscriptionsToBootnodes(ctx, 1), context.DeadlineExceeded) expectedAddressesToAdd := make(map[string]struct{}, len(addressesToAdd)+len(storedAddresses)) for _, addr := range addressesToAdd { @@ -662,7 +662,7 @@ func TestUnreliableSubscriptionToBootnodes(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), tc.timeOut) defer cancel() - err := client.makeSubscribtionsToBootnodes(ctx, 1) + err := client.makeSubscriptionsToBootnodes(ctx, 1) require.ErrorIs(t, err, tc.expectedErr) }) } diff --git a/l1/l1_test.go b/l1/l1_test.go index 3095328195..ccd54f6902 100644 --- a/l1/l1_test.go +++ b/l1/l1_test.go @@ -171,7 +171,7 @@ func TestEventListener(t *testing.T) { }) ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond) - require.NoError(t, client.Run(ctx)) + require.ErrorIs(t, client.Run(ctx), context.DeadlineExceeded) cancel() require.Equal(t, &core.L1Head{