From 12471d53333b9f64a83be123e5a33eb0b18dfddb Mon Sep 17 00:00:00 2001 From: thomaspanf Date: Mon, 4 Nov 2024 14:27:16 +0800 Subject: [PATCH 1/5] Use signalling instead of old system in metrics-exporter --- rocketpool/node/metrics-exporter.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/rocketpool/node/metrics-exporter.go b/rocketpool/node/metrics-exporter.go index e0555eb85..02e2563bd 100644 --- a/rocketpool/node/metrics-exporter.go +++ b/rocketpool/node/metrics-exporter.go @@ -6,6 +6,7 @@ import ( "os" "strings" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/rocket-pool/smartnode/rocketpool/node/collectors" @@ -37,7 +38,7 @@ func runMetricsServer(c *cli.Context, logger log.ColorLogger, stateLocker *colle if err != nil { return err } - s, err := services.GetSnapshotDelegation(c) + reg, err := services.GetRocketSignerRegistry(c) if err != nil { return err } @@ -80,14 +81,14 @@ func runMetricsServer(c *cli.Context, logger log.ColorLogger, stateLocker *colle registry.MustRegister(smoothingPoolCollector) // Set up snapshot checking if enabled - votingId := cfg.Smartnode.GetVotingSnapshotID() - if s != nil { - votingDelegate, err := s.Delegation(nil, nodeAccount.Address, votingId) + if cfg.Smartnode.GetRocketSignerRegistryAddress() != "" { + signallingAddress, err := reg.NodeToSigner(&bind.CallOpts{}, nodeAccount.Address) if err != nil { - return fmt.Errorf("Error getting node delegate: %w", err) + return fmt.Errorf("Error getting the signalling address: %w", err) } - snapshotCollector := collectors.NewSnapshotCollector(rp, cfg, nodeAccount.Address, votingDelegate) + snapshotCollector := collectors.NewSnapshotCollector(rp, cfg, nodeAccount.Address, signallingAddress) registry.MustRegister(snapshotCollector) + } // Start the HTTP server From 8541edbc5bb712e3e45312e125e736258e09e3db Mon Sep 17 00:00:00 2001 From: thomaspanf Date: Mon, 4 Nov 2024 14:34:35 +0800 Subject: [PATCH 2/5] Deprecate SnapshotDelegation --- shared/services/config/smartnode-config.go | 13 - .../services/contracts/snapshot-delegation.go | 577 ------------------ shared/services/rocketpool/node.go | 64 -- shared/services/services.go | 25 - shared/types/api/node.go | 24 - 5 files changed, 703 deletions(-) delete mode 100644 shared/services/contracts/snapshot-delegation.go diff --git a/shared/services/config/smartnode-config.go b/shared/services/config/smartnode-config.go index f04aaf3ec..e1eb8ff91 100644 --- a/shared/services/config/smartnode-config.go +++ b/shared/services/config/smartnode-config.go @@ -135,9 +135,6 @@ type SmartnodeConfig struct { // The contract address of the RPL token rplTokenAddress map[config.Network]string `yaml:"-"` - // The contract address for Snapshot delegation - snapshotDelegationAddress map[config.Network]string `yaml:"-"` - // The Snapshot API domain snapshotApiDomain map[config.Network]string `yaml:"-"` @@ -569,12 +566,6 @@ func NewSmartnodeConfig(cfg *RocketPoolConfig) *SmartnodeConfig { config.Network_Holesky: "0x9294Fc6F03c64Cc217f5BE8697EA3Ed2De77e2F8", }, - snapshotDelegationAddress: map[config.Network]string{ - config.Network_Mainnet: "0x469788fE6E9E9681C6ebF3bF78e7Fd26Fc015446", - config.Network_Devnet: "", - config.Network_Holesky: "", - }, - snapshotApiDomain: map[config.Network]string{ config.Network_Mainnet: "hub.snapshot.org", config.Network_Devnet: "", @@ -802,10 +793,6 @@ func (cfg *SmartnodeConfig) GetRplTokenAddress() string { return cfg.rplTokenAddress[cfg.Network.Value.(config.Network)] } -func (cfg *SmartnodeConfig) GetSnapshotDelegationAddress() string { - return cfg.snapshotDelegationAddress[cfg.Network.Value.(config.Network)] -} - func (cfg *SmartnodeConfig) GetSmartnodeContainerTag() string { return smartnodeTag } diff --git a/shared/services/contracts/snapshot-delegation.go b/shared/services/contracts/snapshot-delegation.go deleted file mode 100644 index a62359068..000000000 --- a/shared/services/contracts/snapshot-delegation.go +++ /dev/null @@ -1,577 +0,0 @@ -// Code generated - DO NOT EDIT. -// This file is a generated binding and any manual changes will be lost. - -package contracts - -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 -) - -// SnapshotDelegationMetaData contains all meta data concerning the SnapshotDelegation contract. -var SnapshotDelegationMetaData = &bind.MetaData{ - ABI: "[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"delegator\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"id\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"delegate\",\"type\":\"address\"}],\"name\":\"ClearDelegate\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"delegator\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"id\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"delegate\",\"type\":\"address\"}],\"name\":\"SetDelegate\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"id\",\"type\":\"bytes32\"}],\"name\":\"clearDelegate\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"},{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"delegation\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"id\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"delegate\",\"type\":\"address\"}],\"name\":\"setDelegate\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", -} - -// SnapshotDelegationABI is the input ABI used to generate the binding from. -// Deprecated: Use SnapshotDelegationMetaData.ABI instead. -var SnapshotDelegationABI = SnapshotDelegationMetaData.ABI - -// SnapshotDelegation is an auto generated Go binding around an Ethereum contract. -type SnapshotDelegation struct { - SnapshotDelegationCaller // Read-only binding to the contract - SnapshotDelegationTransactor // Write-only binding to the contract - SnapshotDelegationFilterer // Log filterer for contract events -} - -// SnapshotDelegationCaller is an auto generated read-only Go binding around an Ethereum contract. -type SnapshotDelegationCaller struct { - contract *bind.BoundContract // Generic contract wrapper for the low level calls -} - -// SnapshotDelegationTransactor is an auto generated write-only Go binding around an Ethereum contract. -type SnapshotDelegationTransactor struct { - contract *bind.BoundContract // Generic contract wrapper for the low level calls -} - -// SnapshotDelegationFilterer is an auto generated log filtering Go binding around an Ethereum contract events. -type SnapshotDelegationFilterer struct { - contract *bind.BoundContract // Generic contract wrapper for the low level calls -} - -// SnapshotDelegationSession is an auto generated Go binding around an Ethereum contract, -// with pre-set call and transact options. -type SnapshotDelegationSession struct { - Contract *SnapshotDelegation // 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 -} - -// SnapshotDelegationCallerSession is an auto generated read-only Go binding around an Ethereum contract, -// with pre-set call options. -type SnapshotDelegationCallerSession struct { - Contract *SnapshotDelegationCaller // Generic contract caller binding to set the session for - CallOpts bind.CallOpts // Call options to use throughout this session -} - -// SnapshotDelegationTransactorSession is an auto generated write-only Go binding around an Ethereum contract, -// with pre-set transact options. -type SnapshotDelegationTransactorSession struct { - Contract *SnapshotDelegationTransactor // Generic contract transactor binding to set the session for - TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session -} - -// SnapshotDelegationRaw is an auto generated low-level Go binding around an Ethereum contract. -type SnapshotDelegationRaw struct { - Contract *SnapshotDelegation // Generic contract binding to access the raw methods on -} - -// SnapshotDelegationCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. -type SnapshotDelegationCallerRaw struct { - Contract *SnapshotDelegationCaller // Generic read-only contract binding to access the raw methods on -} - -// SnapshotDelegationTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. -type SnapshotDelegationTransactorRaw struct { - Contract *SnapshotDelegationTransactor // Generic write-only contract binding to access the raw methods on -} - -// NewSnapshotDelegation creates a new instance of SnapshotDelegation, bound to a specific deployed contract. -func NewSnapshotDelegation(address common.Address, backend bind.ContractBackend) (*SnapshotDelegation, error) { - contract, err := bindSnapshotDelegation(address, backend, backend, backend) - if err != nil { - return nil, err - } - return &SnapshotDelegation{SnapshotDelegationCaller: SnapshotDelegationCaller{contract: contract}, SnapshotDelegationTransactor: SnapshotDelegationTransactor{contract: contract}, SnapshotDelegationFilterer: SnapshotDelegationFilterer{contract: contract}}, nil -} - -// NewSnapshotDelegationCaller creates a new read-only instance of SnapshotDelegation, bound to a specific deployed contract. -func NewSnapshotDelegationCaller(address common.Address, caller bind.ContractCaller) (*SnapshotDelegationCaller, error) { - contract, err := bindSnapshotDelegation(address, caller, nil, nil) - if err != nil { - return nil, err - } - return &SnapshotDelegationCaller{contract: contract}, nil -} - -// NewSnapshotDelegationTransactor creates a new write-only instance of SnapshotDelegation, bound to a specific deployed contract. -func NewSnapshotDelegationTransactor(address common.Address, transactor bind.ContractTransactor) (*SnapshotDelegationTransactor, error) { - contract, err := bindSnapshotDelegation(address, nil, transactor, nil) - if err != nil { - return nil, err - } - return &SnapshotDelegationTransactor{contract: contract}, nil -} - -// NewSnapshotDelegationFilterer creates a new log filterer instance of SnapshotDelegation, bound to a specific deployed contract. -func NewSnapshotDelegationFilterer(address common.Address, filterer bind.ContractFilterer) (*SnapshotDelegationFilterer, error) { - contract, err := bindSnapshotDelegation(address, nil, nil, filterer) - if err != nil { - return nil, err - } - return &SnapshotDelegationFilterer{contract: contract}, nil -} - -// bindSnapshotDelegation binds a generic wrapper to an already deployed contract. -func bindSnapshotDelegation(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { - parsed, err := abi.JSON(strings.NewReader(SnapshotDelegationABI)) - 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 (_SnapshotDelegation *SnapshotDelegationRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error { - return _SnapshotDelegation.Contract.SnapshotDelegationCaller.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 (_SnapshotDelegation *SnapshotDelegationRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { - return _SnapshotDelegation.Contract.SnapshotDelegationTransactor.contract.Transfer(opts) -} - -// Transact invokes the (paid) contract method with params as input values. -func (_SnapshotDelegation *SnapshotDelegationRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { - return _SnapshotDelegation.Contract.SnapshotDelegationTransactor.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 (_SnapshotDelegation *SnapshotDelegationCallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error { - return _SnapshotDelegation.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 (_SnapshotDelegation *SnapshotDelegationTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { - return _SnapshotDelegation.Contract.contract.Transfer(opts) -} - -// Transact invokes the (paid) contract method with params as input values. -func (_SnapshotDelegation *SnapshotDelegationTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { - return _SnapshotDelegation.Contract.contract.Transact(opts, method, params...) -} - -// Delegation is a free data retrieval call binding the contract method 0x74c6c454. -// -// Solidity: function delegation(address , bytes32 ) view returns(address) -func (_SnapshotDelegation *SnapshotDelegationCaller) Delegation(opts *bind.CallOpts, arg0 common.Address, arg1 [32]byte) (common.Address, error) { - var out []interface{} - err := _SnapshotDelegation.contract.Call(opts, &out, "delegation", arg0, arg1) - - if err != nil { - return *new(common.Address), err - } - - out0 := *abi.ConvertType(out[0], new(common.Address)).(*common.Address) - - return out0, err - -} - -// Delegation is a free data retrieval call binding the contract method 0x74c6c454. -// -// Solidity: function delegation(address , bytes32 ) view returns(address) -func (_SnapshotDelegation *SnapshotDelegationSession) Delegation(arg0 common.Address, arg1 [32]byte) (common.Address, error) { - return _SnapshotDelegation.Contract.Delegation(&_SnapshotDelegation.CallOpts, arg0, arg1) -} - -// Delegation is a free data retrieval call binding the contract method 0x74c6c454. -// -// Solidity: function delegation(address , bytes32 ) view returns(address) -func (_SnapshotDelegation *SnapshotDelegationCallerSession) Delegation(arg0 common.Address, arg1 [32]byte) (common.Address, error) { - return _SnapshotDelegation.Contract.Delegation(&_SnapshotDelegation.CallOpts, arg0, arg1) -} - -// ClearDelegate is a paid mutator transaction binding the contract method 0xf0bedbe2. -// -// Solidity: function clearDelegate(bytes32 id) returns() -func (_SnapshotDelegation *SnapshotDelegationTransactor) ClearDelegate(opts *bind.TransactOpts, id [32]byte) (*types.Transaction, error) { - return _SnapshotDelegation.contract.Transact(opts, "clearDelegate", id) -} - -// ClearDelegate is a paid mutator transaction binding the contract method 0xf0bedbe2. -// -// Solidity: function clearDelegate(bytes32 id) returns() -func (_SnapshotDelegation *SnapshotDelegationSession) ClearDelegate(id [32]byte) (*types.Transaction, error) { - return _SnapshotDelegation.Contract.ClearDelegate(&_SnapshotDelegation.TransactOpts, id) -} - -// ClearDelegate is a paid mutator transaction binding the contract method 0xf0bedbe2. -// -// Solidity: function clearDelegate(bytes32 id) returns() -func (_SnapshotDelegation *SnapshotDelegationTransactorSession) ClearDelegate(id [32]byte) (*types.Transaction, error) { - return _SnapshotDelegation.Contract.ClearDelegate(&_SnapshotDelegation.TransactOpts, id) -} - -// SetDelegate is a paid mutator transaction binding the contract method 0xbd86e508. -// -// Solidity: function setDelegate(bytes32 id, address delegate) returns() -func (_SnapshotDelegation *SnapshotDelegationTransactor) SetDelegate(opts *bind.TransactOpts, id [32]byte, delegate common.Address) (*types.Transaction, error) { - return _SnapshotDelegation.contract.Transact(opts, "setDelegate", id, delegate) -} - -// SetDelegate is a paid mutator transaction binding the contract method 0xbd86e508. -// -// Solidity: function setDelegate(bytes32 id, address delegate) returns() -func (_SnapshotDelegation *SnapshotDelegationSession) SetDelegate(id [32]byte, delegate common.Address) (*types.Transaction, error) { - return _SnapshotDelegation.Contract.SetDelegate(&_SnapshotDelegation.TransactOpts, id, delegate) -} - -// SetDelegate is a paid mutator transaction binding the contract method 0xbd86e508. -// -// Solidity: function setDelegate(bytes32 id, address delegate) returns() -func (_SnapshotDelegation *SnapshotDelegationTransactorSession) SetDelegate(id [32]byte, delegate common.Address) (*types.Transaction, error) { - return _SnapshotDelegation.Contract.SetDelegate(&_SnapshotDelegation.TransactOpts, id, delegate) -} - -// SnapshotDelegationClearDelegateIterator is returned from FilterClearDelegate and is used to iterate over the raw logs and unpacked data for ClearDelegate events raised by the SnapshotDelegation contract. -type SnapshotDelegationClearDelegateIterator struct { - Event *SnapshotDelegationClearDelegate // 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 *SnapshotDelegationClearDelegateIterator) 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(SnapshotDelegationClearDelegate) - 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(SnapshotDelegationClearDelegate) - 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 *SnapshotDelegationClearDelegateIterator) Error() error { - return it.fail -} - -// Close terminates the iteration process, releasing any pending underlying -// resources. -func (it *SnapshotDelegationClearDelegateIterator) Close() error { - it.sub.Unsubscribe() - return nil -} - -// SnapshotDelegationClearDelegate represents a ClearDelegate event raised by the SnapshotDelegation contract. -type SnapshotDelegationClearDelegate struct { - Delegator common.Address - Id [32]byte - Delegate common.Address - Raw types.Log // Blockchain specific contextual infos -} - -// FilterClearDelegate is a free log retrieval operation binding the contract event 0x9c4f00c4291262731946e308dc2979a56bd22cce8f95906b975065e96cd5a064. -// -// Solidity: event ClearDelegate(address indexed delegator, bytes32 indexed id, address indexed delegate) -func (_SnapshotDelegation *SnapshotDelegationFilterer) FilterClearDelegate(opts *bind.FilterOpts, delegator []common.Address, id [][32]byte, delegate []common.Address) (*SnapshotDelegationClearDelegateIterator, error) { - - var delegatorRule []interface{} - for _, delegatorItem := range delegator { - delegatorRule = append(delegatorRule, delegatorItem) - } - var idRule []interface{} - for _, idItem := range id { - idRule = append(idRule, idItem) - } - var delegateRule []interface{} - for _, delegateItem := range delegate { - delegateRule = append(delegateRule, delegateItem) - } - - logs, sub, err := _SnapshotDelegation.contract.FilterLogs(opts, "ClearDelegate", delegatorRule, idRule, delegateRule) - if err != nil { - return nil, err - } - return &SnapshotDelegationClearDelegateIterator{contract: _SnapshotDelegation.contract, event: "ClearDelegate", logs: logs, sub: sub}, nil -} - -// WatchClearDelegate is a free log subscription operation binding the contract event 0x9c4f00c4291262731946e308dc2979a56bd22cce8f95906b975065e96cd5a064. -// -// Solidity: event ClearDelegate(address indexed delegator, bytes32 indexed id, address indexed delegate) -func (_SnapshotDelegation *SnapshotDelegationFilterer) WatchClearDelegate(opts *bind.WatchOpts, sink chan<- *SnapshotDelegationClearDelegate, delegator []common.Address, id [][32]byte, delegate []common.Address) (event.Subscription, error) { - - var delegatorRule []interface{} - for _, delegatorItem := range delegator { - delegatorRule = append(delegatorRule, delegatorItem) - } - var idRule []interface{} - for _, idItem := range id { - idRule = append(idRule, idItem) - } - var delegateRule []interface{} - for _, delegateItem := range delegate { - delegateRule = append(delegateRule, delegateItem) - } - - logs, sub, err := _SnapshotDelegation.contract.WatchLogs(opts, "ClearDelegate", delegatorRule, idRule, delegateRule) - 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(SnapshotDelegationClearDelegate) - if err := _SnapshotDelegation.contract.UnpackLog(event, "ClearDelegate", 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 -} - -// ParseClearDelegate is a log parse operation binding the contract event 0x9c4f00c4291262731946e308dc2979a56bd22cce8f95906b975065e96cd5a064. -// -// Solidity: event ClearDelegate(address indexed delegator, bytes32 indexed id, address indexed delegate) -func (_SnapshotDelegation *SnapshotDelegationFilterer) ParseClearDelegate(log types.Log) (*SnapshotDelegationClearDelegate, error) { - event := new(SnapshotDelegationClearDelegate) - if err := _SnapshotDelegation.contract.UnpackLog(event, "ClearDelegate", log); err != nil { - return nil, err - } - event.Raw = log - return event, nil -} - -// SnapshotDelegationSetDelegateIterator is returned from FilterSetDelegate and is used to iterate over the raw logs and unpacked data for SetDelegate events raised by the SnapshotDelegation contract. -type SnapshotDelegationSetDelegateIterator struct { - Event *SnapshotDelegationSetDelegate // 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 *SnapshotDelegationSetDelegateIterator) 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(SnapshotDelegationSetDelegate) - 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(SnapshotDelegationSetDelegate) - 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 *SnapshotDelegationSetDelegateIterator) Error() error { - return it.fail -} - -// Close terminates the iteration process, releasing any pending underlying -// resources. -func (it *SnapshotDelegationSetDelegateIterator) Close() error { - it.sub.Unsubscribe() - return nil -} - -// SnapshotDelegationSetDelegate represents a SetDelegate event raised by the SnapshotDelegation contract. -type SnapshotDelegationSetDelegate struct { - Delegator common.Address - Id [32]byte - Delegate common.Address - Raw types.Log // Blockchain specific contextual infos -} - -// FilterSetDelegate is a free log retrieval operation binding the contract event 0xa9a7fd460f56bddb880a465a9c3e9730389c70bc53108148f16d55a87a6c468e. -// -// Solidity: event SetDelegate(address indexed delegator, bytes32 indexed id, address indexed delegate) -func (_SnapshotDelegation *SnapshotDelegationFilterer) FilterSetDelegate(opts *bind.FilterOpts, delegator []common.Address, id [][32]byte, delegate []common.Address) (*SnapshotDelegationSetDelegateIterator, error) { - - var delegatorRule []interface{} - for _, delegatorItem := range delegator { - delegatorRule = append(delegatorRule, delegatorItem) - } - var idRule []interface{} - for _, idItem := range id { - idRule = append(idRule, idItem) - } - var delegateRule []interface{} - for _, delegateItem := range delegate { - delegateRule = append(delegateRule, delegateItem) - } - - logs, sub, err := _SnapshotDelegation.contract.FilterLogs(opts, "SetDelegate", delegatorRule, idRule, delegateRule) - if err != nil { - return nil, err - } - return &SnapshotDelegationSetDelegateIterator{contract: _SnapshotDelegation.contract, event: "SetDelegate", logs: logs, sub: sub}, nil -} - -// WatchSetDelegate is a free log subscription operation binding the contract event 0xa9a7fd460f56bddb880a465a9c3e9730389c70bc53108148f16d55a87a6c468e. -// -// Solidity: event SetDelegate(address indexed delegator, bytes32 indexed id, address indexed delegate) -func (_SnapshotDelegation *SnapshotDelegationFilterer) WatchSetDelegate(opts *bind.WatchOpts, sink chan<- *SnapshotDelegationSetDelegate, delegator []common.Address, id [][32]byte, delegate []common.Address) (event.Subscription, error) { - - var delegatorRule []interface{} - for _, delegatorItem := range delegator { - delegatorRule = append(delegatorRule, delegatorItem) - } - var idRule []interface{} - for _, idItem := range id { - idRule = append(idRule, idItem) - } - var delegateRule []interface{} - for _, delegateItem := range delegate { - delegateRule = append(delegateRule, delegateItem) - } - - logs, sub, err := _SnapshotDelegation.contract.WatchLogs(opts, "SetDelegate", delegatorRule, idRule, delegateRule) - 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(SnapshotDelegationSetDelegate) - if err := _SnapshotDelegation.contract.UnpackLog(event, "SetDelegate", 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 -} - -// ParseSetDelegate is a log parse operation binding the contract event 0xa9a7fd460f56bddb880a465a9c3e9730389c70bc53108148f16d55a87a6c468e. -// -// Solidity: event SetDelegate(address indexed delegator, bytes32 indexed id, address indexed delegate) -func (_SnapshotDelegation *SnapshotDelegationFilterer) ParseSetDelegate(log types.Log) (*SnapshotDelegationSetDelegate, error) { - event := new(SnapshotDelegationSetDelegate) - if err := _SnapshotDelegation.contract.UnpackLog(event, "SetDelegate", log); err != nil { - return nil, err - } - event.Raw = log - return event, nil -} diff --git a/shared/services/rocketpool/node.go b/shared/services/rocketpool/node.go index ce754cf1d..e74cdca81 100644 --- a/shared/services/rocketpool/node.go +++ b/shared/services/rocketpool/node.go @@ -744,70 +744,6 @@ func (c *Client) DepositContractInfo() (api.DepositContractInfoResponse, error) return response, nil } -// Estimate the gas required to set a voting snapshot delegate -func (c *Client) EstimateSetSnapshotDelegateGas(address common.Address) (api.EstimateSetSnapshotDelegateGasResponse, error) { - responseBytes, err := c.callAPI(fmt.Sprintf("node estimate-set-snapshot-delegate-gas %s", address.Hex())) - if err != nil { - return api.EstimateSetSnapshotDelegateGasResponse{}, fmt.Errorf("Could not get estimate-set-snapshot-delegate-gas response: %w", err) - } - var response api.EstimateSetSnapshotDelegateGasResponse - if err := json.Unmarshal(responseBytes, &response); err != nil { - return api.EstimateSetSnapshotDelegateGasResponse{}, fmt.Errorf("Could not decode estimate-set-snapshot-delegate-gas response: %w", err) - } - if response.Error != "" { - return api.EstimateSetSnapshotDelegateGasResponse{}, fmt.Errorf("Could not get estimate-set-snapshot-delegate-gas response: %s", response.Error) - } - return response, nil -} - -// Set a voting snapshot delegate for the node -func (c *Client) SetSnapshotDelegate(address common.Address) (api.SetSnapshotDelegateResponse, error) { - responseBytes, err := c.callAPI(fmt.Sprintf("node set-snapshot-delegate %s", address.Hex())) - if err != nil { - return api.SetSnapshotDelegateResponse{}, fmt.Errorf("Could not get set-snapshot-delegate response: %w", err) - } - var response api.SetSnapshotDelegateResponse - if err := json.Unmarshal(responseBytes, &response); err != nil { - return api.SetSnapshotDelegateResponse{}, fmt.Errorf("Could not decode set-snapshot-delegate response: %w", err) - } - if response.Error != "" { - return api.SetSnapshotDelegateResponse{}, fmt.Errorf("Could not get set-snapshot-delegate response: %s", response.Error) - } - return response, nil -} - -// Estimate the gas required to clear the node's voting snapshot delegate -func (c *Client) EstimateClearSnapshotDelegateGas() (api.EstimateClearSnapshotDelegateGasResponse, error) { - responseBytes, err := c.callAPI("node estimate-clear-snapshot-delegate-gas") - if err != nil { - return api.EstimateClearSnapshotDelegateGasResponse{}, fmt.Errorf("Could not get estimate-clear-snapshot-delegate-gas response: %w", err) - } - var response api.EstimateClearSnapshotDelegateGasResponse - if err := json.Unmarshal(responseBytes, &response); err != nil { - return api.EstimateClearSnapshotDelegateGasResponse{}, fmt.Errorf("Could not decode estimate-clear-snapshot-delegate-gas response: %w", err) - } - if response.Error != "" { - return api.EstimateClearSnapshotDelegateGasResponse{}, fmt.Errorf("Could not get estimate-clear-snapshot-delegate-gas response: %s", response.Error) - } - return response, nil -} - -// Clear the node's voting snapshot delegate -func (c *Client) ClearSnapshotDelegate() (api.ClearSnapshotDelegateResponse, error) { - responseBytes, err := c.callAPI("node clear-snapshot-delegate") - if err != nil { - return api.ClearSnapshotDelegateResponse{}, fmt.Errorf("Could not get clear-snapshot-delegate response: %w", err) - } - var response api.ClearSnapshotDelegateResponse - if err := json.Unmarshal(responseBytes, &response); err != nil { - return api.ClearSnapshotDelegateResponse{}, fmt.Errorf("Could not decode clear-snapshot-delegate response: %w", err) - } - if response.Error != "" { - return api.ClearSnapshotDelegateResponse{}, fmt.Errorf("Could not get clear-snapshot-delegate response: %s", response.Error) - } - return response, nil -} - // Get the initialization status of the fee distributor contract func (c *Client) IsFeeDistributorInitialized() (api.NodeIsFeeDistributorInitializedResponse, error) { responseBytes, err := c.callAPI("node is-fee-distributor-initialized") diff --git a/shared/services/services.go b/shared/services/services.go index 994cbb21e..0edb98b5f 100644 --- a/shared/services/services.go +++ b/shared/services/services.go @@ -39,7 +39,6 @@ var ( ecManager *ExecutionClientManager bcManager *BeaconClientManager rocketPool *rocketpool.RocketPool - snapshotDelegation *contracts.SnapshotDelegation rocketSignerRegistry *contracts.RocketSignerRegistry beaconClient beacon.Client docker *client.Client @@ -51,7 +50,6 @@ var ( initBCManager sync.Once initRocketPool sync.Once initOneInchOracle sync.Once - initSnapshotDelegation sync.Once initRocketSignerRegistry sync.Once initBeaconClient sync.Once initDocker sync.Once @@ -125,18 +123,6 @@ func GetRocketSignerRegistry(c *cli.Context) (*contracts.RocketSignerRegistry, e return getRocketSignerRegistry(cfg, ec) } -func GetSnapshotDelegation(c *cli.Context) (*contracts.SnapshotDelegation, error) { - cfg, err := getConfig(c) - if err != nil { - return nil, err - } - ec, err := getEthClient(c, cfg) - if err != nil { - return nil, err - } - return getSnapshotDelegation(cfg, ec) -} - func GetBeaconClient(c *cli.Context) (*BeaconClientManager, error) { cfg, err := getConfig(c) if err != nil { @@ -256,17 +242,6 @@ func getRocketSignerRegistry(cfg *config.RocketPoolConfig, client rocketpool.Exe return rocketSignerRegistry, err } -func getSnapshotDelegation(cfg *config.RocketPoolConfig, client rocketpool.ExecutionClient) (*contracts.SnapshotDelegation, error) { - var err error - initSnapshotDelegation.Do(func() { - address := cfg.Smartnode.GetSnapshotDelegationAddress() - if address != "" { - snapshotDelegation, err = contracts.NewSnapshotDelegation(common.HexToAddress(address), client) - } - }) - return snapshotDelegation, err -} - func getBeaconClient(c *cli.Context, cfg *config.RocketPoolConfig) (*BeaconClientManager, error) { var err error initBCManager.Do(func() { diff --git a/shared/types/api/node.go b/shared/types/api/node.go index e7613cfa0..1ae3817d7 100644 --- a/shared/types/api/node.go +++ b/shared/types/api/node.go @@ -497,30 +497,6 @@ type NodeSignResponse struct { SignedData string `json:"signedData"` } -type EstimateSetSnapshotDelegateGasResponse struct { - Status string `json:"status"` - Error string `json:"error"` - GasInfo rocketpool.GasInfo `json:"gasInfo"` -} - -type SetSnapshotDelegateResponse struct { - Status string `json:"status"` - Error string `json:"error"` - TxHash common.Hash `json:"txHash"` -} - -type EstimateClearSnapshotDelegateGasResponse struct { - Status string `json:"status"` - Error string `json:"error"` - GasInfo rocketpool.GasInfo `json:"gasInfo"` -} - -type ClearSnapshotDelegateResponse struct { - Status string `json:"status"` - Error string `json:"error"` - TxHash common.Hash `json:"txHash"` -} - type NodeIsFeeDistributorInitializedResponse struct { Status string `json:"status"` Error string `json:"error"` From 98be8e1c63fab2936e0aef212cbc26cf126669dc Mon Sep 17 00:00:00 2001 From: thomaspanf Date: Fri, 22 Nov 2024 16:03:04 +0800 Subject: [PATCH 3/5] Update snapshot-collector api calls to correctly grab voting power and snapshot voted proposals --- .../node/collectors/snapshot-collector.go | 120 ++++++++++++++---- rocketpool/node/metrics-exporter.go | 7 +- 2 files changed, 101 insertions(+), 26 deletions(-) diff --git a/rocketpool/node/collectors/snapshot-collector.go b/rocketpool/node/collectors/snapshot-collector.go index 76b382cc7..35d1db6b2 100644 --- a/rocketpool/node/collectors/snapshot-collector.go +++ b/rocketpool/node/collectors/snapshot-collector.go @@ -1,14 +1,19 @@ package collectors import ( + "context" "fmt" + "strconv" "time" "github.com/ethereum/go-ethereum/common" "github.com/prometheus/client_golang/prometheus" + "github.com/rocket-pool/rocketpool-go/network" "github.com/rocket-pool/rocketpool-go/rocketpool" "github.com/rocket-pool/smartnode/rocketpool/api/pdao" + "github.com/rocket-pool/smartnode/shared/services" "github.com/rocket-pool/smartnode/shared/services/config" + "github.com/rocket-pool/smartnode/shared/services/proposals" "golang.org/x/sync/errgroup" ) @@ -35,14 +40,23 @@ type SnapshotCollector struct { // The current delegate voting power on Snapshot delegateVotingPower *prometheus.Desc + // The Rocket Pool Contract manager + rp *rocketpool.RocketPool + // The Rocket Pool config cfg *config.RocketPoolConfig + // The Rocket Pool Execution Client manager + ec *services.ExecutionClientManager + + // The Rocket Pool Beacon Client manager + bc *services.BeaconClientManager + // the node wallet address nodeAddress common.Address - // the delegate address - delegateAddress common.Address + // the signalling address + signallingAddress common.Address // Store values from the latest API call cachedNodeVotingPower float64 @@ -60,7 +74,7 @@ type SnapshotCollector struct { } // Create a new SnapshotCollector instance -func NewSnapshotCollector(rp *rocketpool.RocketPool, cfg *config.RocketPoolConfig, nodeAddress common.Address, delegateAddress common.Address) *SnapshotCollector { +func NewSnapshotCollector(rp *rocketpool.RocketPool, cfg *config.RocketPoolConfig, ec *services.ExecutionClientManager, bc *services.BeaconClientManager, nodeAddress common.Address, signallingAddress common.Address) *SnapshotCollector { subsystem := "snapshot" return &SnapshotCollector{ activeProposals: prometheus.NewDesc(prometheus.BuildFQName(namespace, subsystem, "proposals_active"), @@ -87,10 +101,13 @@ func NewSnapshotCollector(rp *rocketpool.RocketPool, cfg *config.RocketPoolConfi "The delegate current voting power on Snapshot", nil, nil, ), - cfg: cfg, - nodeAddress: nodeAddress, - delegateAddress: delegateAddress, - logPrefix: "Snapshot Collector", + rp: rp, + cfg: cfg, + ec: ec, + bc: bc, + nodeAddress: nodeAddress, + signallingAddress: signallingAddress, + logPrefix: "Snapshot Collector", } } @@ -109,6 +126,11 @@ func (collector *SnapshotCollector) Collect(channel chan<- prometheus.Metric) { // Sync var wg errgroup.Group + var err error + var propMgr *proposals.ProposalManager + var blockNumber uint64 + var onchainVotingDelegate common.Address + var isVotingInitialized bool activeProposals := float64(0) closedProposals := float64(0) votesActiveProposals := float64(0) @@ -118,7 +140,7 @@ func (collector *SnapshotCollector) Collect(channel chan<- prometheus.Metric) { // Get the number of votes on Snapshot proposals wg.Go(func() error { if time.Since(collector.lastApiCallTimestamp).Hours() >= hoursToWait { - votedProposals, err := pdao.GetSnapshotVotedProposals(collector.cfg.Smartnode.GetSnapshotApiDomain(), collector.cfg.Smartnode.GetSnapshotID(), collector.nodeAddress, collector.delegateAddress) + votedProposals, err := pdao.GetSnapshotVotedProposals(collector.cfg.Smartnode.GetSnapshotApiDomain(), collector.cfg.Smartnode.GetSnapshotID(), collector.nodeAddress, collector.signallingAddress) if err != nil { return fmt.Errorf("Error getting Snapshot voted proposals: %w", err) } @@ -164,31 +186,41 @@ func (collector *SnapshotCollector) Collect(channel chan<- prometheus.Metric) { return nil }) - // Get the node's voting power + // Get latest block number wg.Go(func() error { - if time.Since(collector.lastApiCallTimestamp).Hours() >= hoursToWait { - - votingPowerResponse, err := pdao.GetSnapshotVotingPower(collector.cfg.Smartnode.GetSnapshotApiDomain(), collector.cfg.Smartnode.GetSnapshotID(), collector.nodeAddress) - if err != nil { - return fmt.Errorf("Error getting Snapshot voted proposals for node address: %w", err) - } + blockNumber, err = collector.ec.BlockNumber(context.Background()) + if err != nil { + return fmt.Errorf("Error getting block number: %w", err) + } + return nil + }) - collector.cachedNodeVotingPower = votingPowerResponse.Data.Vp.Vp + // Get the propMgr + wg.Go(func() error { + propMgr, err = proposals.NewProposalManager(nil, collector.cfg, collector.rp, collector.bc) + if err != nil { + return fmt.Errorf("Error getting the prop manager: %w", err) } return nil }) - // Get the delegate's voting power + // Get the node onchain voting delegate wg.Go(func() error { - if time.Since(collector.lastApiCallTimestamp).Hours() >= hoursToWait { - votingPowerResponse, err := pdao.GetSnapshotVotingPower(collector.cfg.Smartnode.GetSnapshotApiDomain(), collector.cfg.Smartnode.GetSnapshotID(), collector.delegateAddress) - if err != nil { - return fmt.Errorf("Error getting Snapshot voted proposals for delegate address: %w", err) - } + var err error + onchainVotingDelegate, err = network.GetCurrentVotingDelegate(collector.rp, collector.nodeAddress, nil) + if err != nil { + return fmt.Errorf("Error getting the on-chain voting delegate: %w", err) + } + return err + }) - collector.cachedDelegateVotingPower = votingPowerResponse.Data.Vp.Vp + // Get Voting Initialized status + wg.Go(func() error { + isVotingInitialized, err = network.GetVotingInitialized(collector.rp, collector.nodeAddress, nil) + if err != nil { + return fmt.Errorf("Error checking if voting is initialized: %w", err) } - return nil + return err }) // Wait for data @@ -196,6 +228,30 @@ func (collector *SnapshotCollector) Collect(channel chan<- prometheus.Metric) { collector.logError(err) return } + + // Check if sufficient time has passed and voting is initialized + if time.Since(collector.lastApiCallTimestamp).Hours() >= hoursToWait && isVotingInitialized { + // Get voting power for the node + nodeVotingPower, err := getVotingPower(propMgr, uint32(blockNumber), collector.nodeAddress) + if err != nil { + collector.logError(fmt.Errorf("error getting node voting power: %w", err)) + collector.cachedNodeVotingPower = 0 + } else { + collector.cachedNodeVotingPower = nodeVotingPower + } + // Get voting power for the delegate + delegateVotingPower, err := getVotingPower(propMgr, uint32(blockNumber), onchainVotingDelegate) + if err != nil { + collector.logError(fmt.Errorf("error getting delegate voting power: %w", err)) + collector.cachedDelegateVotingPower = 0 + } else { + collector.cachedDelegateVotingPower = delegateVotingPower + } + } else { + collector.cachedNodeVotingPower = 0 + collector.cachedDelegateVotingPower = 0 + } + if time.Since(collector.lastApiCallTimestamp).Hours() >= hoursToWait { collector.lastApiCallTimestamp = time.Now() } @@ -218,3 +274,19 @@ func (collector *SnapshotCollector) Collect(channel chan<- prometheus.Metric) { func (collector *SnapshotCollector) logError(err error) { fmt.Printf("[%s] %s\n", collector.logPrefix, err.Error()) } + +func getVotingPower(propMgr *proposals.ProposalManager, blockNumber uint32, address common.Address) (float64, error) { + // Get the total voting power + totalDelegatedVP, _, _, err := propMgr.GetArtifactsForVoting(blockNumber, address) + if err != nil { + return 0, fmt.Errorf("error getting voting power: %w", err) + } + + // Parse voting power to float64 + votingPower, err := strconv.ParseFloat(totalDelegatedVP.String(), 64) + if err != nil { + return 0, fmt.Errorf("error parsing voting power: %w", err) + } + + return votingPower, nil +} diff --git a/rocketpool/node/metrics-exporter.go b/rocketpool/node/metrics-exporter.go index 02e2563bd..0361fe8eb 100644 --- a/rocketpool/node/metrics-exporter.go +++ b/rocketpool/node/metrics-exporter.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/rocket-pool/smartnode/rocketpool/node/collectors" @@ -84,9 +85,11 @@ func runMetricsServer(c *cli.Context, logger log.ColorLogger, stateLocker *colle if cfg.Smartnode.GetRocketSignerRegistryAddress() != "" { signallingAddress, err := reg.NodeToSigner(&bind.CallOpts{}, nodeAccount.Address) if err != nil { - return fmt.Errorf("Error getting the signalling address: %w", err) + logger.Printlnf("Error getting the signalling address: %w", err) + // Set signallingAddress to blank address instead of erroring out of the task loop. + signallingAddress = common.Address{} } - snapshotCollector := collectors.NewSnapshotCollector(rp, cfg, nodeAccount.Address, signallingAddress) + snapshotCollector := collectors.NewSnapshotCollector(rp, cfg, ec, bc, nodeAccount.Address, signallingAddress) registry.MustRegister(snapshotCollector) } From 7b2cc220f389a63b6ad5758cc165dd8783e1fe9e Mon Sep 17 00:00:00 2001 From: thomaspanf Date: Wed, 27 Nov 2024 16:44:45 +0800 Subject: [PATCH 4/5] Fixed parsing method and deleted unecessary code --- rocketpool/node/collectors/snapshot-collector.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/rocketpool/node/collectors/snapshot-collector.go b/rocketpool/node/collectors/snapshot-collector.go index 35d1db6b2..71e308317 100644 --- a/rocketpool/node/collectors/snapshot-collector.go +++ b/rocketpool/node/collectors/snapshot-collector.go @@ -3,13 +3,13 @@ package collectors import ( "context" "fmt" - "strconv" "time" "github.com/ethereum/go-ethereum/common" "github.com/prometheus/client_golang/prometheus" "github.com/rocket-pool/rocketpool-go/network" "github.com/rocket-pool/rocketpool-go/rocketpool" + "github.com/rocket-pool/rocketpool-go/utils/eth" "github.com/rocket-pool/smartnode/rocketpool/api/pdao" "github.com/rocket-pool/smartnode/shared/services" "github.com/rocket-pool/smartnode/shared/services/config" @@ -247,9 +247,6 @@ func (collector *SnapshotCollector) Collect(channel chan<- prometheus.Metric) { } else { collector.cachedDelegateVotingPower = delegateVotingPower } - } else { - collector.cachedNodeVotingPower = 0 - collector.cachedDelegateVotingPower = 0 } if time.Since(collector.lastApiCallTimestamp).Hours() >= hoursToWait { @@ -282,11 +279,5 @@ func getVotingPower(propMgr *proposals.ProposalManager, blockNumber uint32, addr return 0, fmt.Errorf("error getting voting power: %w", err) } - // Parse voting power to float64 - votingPower, err := strconv.ParseFloat(totalDelegatedVP.String(), 64) - if err != nil { - return 0, fmt.Errorf("error parsing voting power: %w", err) - } - - return votingPower, nil + return eth.WeiToEth(totalDelegatedVP), nil } From 86a553b3b693520b9a749cc39d67db3f39d1a841 Mon Sep 17 00:00:00 2001 From: thomaspanf Date: Wed, 27 Nov 2024 18:28:44 +0800 Subject: [PATCH 5/5] Added the time.Since check to all calls within goroutine --- .../node/collectors/snapshot-collector.go | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/rocketpool/node/collectors/snapshot-collector.go b/rocketpool/node/collectors/snapshot-collector.go index 71e308317..b710a0c94 100644 --- a/rocketpool/node/collectors/snapshot-collector.go +++ b/rocketpool/node/collectors/snapshot-collector.go @@ -188,37 +188,45 @@ func (collector *SnapshotCollector) Collect(channel chan<- prometheus.Metric) { // Get latest block number wg.Go(func() error { - blockNumber, err = collector.ec.BlockNumber(context.Background()) - if err != nil { - return fmt.Errorf("Error getting block number: %w", err) + if time.Since(collector.lastApiCallTimestamp).Hours() >= hoursToWait { + blockNumber, err = collector.ec.BlockNumber(context.Background()) + if err != nil { + return fmt.Errorf("Error getting block number: %w", err) + } } return nil + }) // Get the propMgr wg.Go(func() error { - propMgr, err = proposals.NewProposalManager(nil, collector.cfg, collector.rp, collector.bc) - if err != nil { - return fmt.Errorf("Error getting the prop manager: %w", err) + if time.Since(collector.lastApiCallTimestamp).Hours() >= hoursToWait { + propMgr, err = proposals.NewProposalManager(nil, collector.cfg, collector.rp, collector.bc) + if err != nil { + return fmt.Errorf("Error getting the prop manager: %w", err) + } } return nil }) // Get the node onchain voting delegate wg.Go(func() error { - var err error - onchainVotingDelegate, err = network.GetCurrentVotingDelegate(collector.rp, collector.nodeAddress, nil) - if err != nil { - return fmt.Errorf("Error getting the on-chain voting delegate: %w", err) + if time.Since(collector.lastApiCallTimestamp).Hours() >= hoursToWait { + onchainVotingDelegate, err = network.GetCurrentVotingDelegate(collector.rp, collector.nodeAddress, nil) + if err != nil { + return fmt.Errorf("Error getting the on-chain voting delegate: %w", err) + } } return err }) // Get Voting Initialized status wg.Go(func() error { - isVotingInitialized, err = network.GetVotingInitialized(collector.rp, collector.nodeAddress, nil) - if err != nil { - return fmt.Errorf("Error checking if voting is initialized: %w", err) + if time.Since(collector.lastApiCallTimestamp).Hours() >= hoursToWait { + isVotingInitialized, err = network.GetVotingInitialized(collector.rp, collector.nodeAddress, nil) + if err != nil { + return fmt.Errorf("Error checking if voting is initialized: %w", err) + } } return err })