Various changes for node

This commit is contained in:
2025-08-17 03:57:57 +00:00
parent 5a1231ae59
commit f5897d4d94
9 changed files with 151 additions and 34 deletions
+8 -7
View File
@@ -15,17 +15,18 @@ import (
type Parameters struct {
// Core sampling parameters
K int `json:"k" yaml:"k"` // sample size per poll
AlphaPreference int `json:"alpha_preference" yaml:"alpha_preference"` // threshold for preference
AlphaConfidence int `json:"alpha_confidence" yaml:"alpha_confidence"` // threshold for confidence
Alpha *int `json:"alpha,omitempty" yaml:"alpha,omitempty"` // deprecated: use AlphaPreference
AlphaPreference int `json:"alphaPreference,omitempty" yaml:"alpha_preference"` // threshold for preference
AlphaConfidence int `json:"alphaConfidence,omitempty" yaml:"alpha_confidence"` // threshold for confidence
Beta uint32 `json:"beta" yaml:"beta"` // consecutive successes for finalize
DeltaMinMS int `json:"delta_min_ms" yaml:"delta_min_ms"` // nominal poll round interval (ms)
// Advanced parameters
ConcurrentPolls int `json:"concurrent_polls" yaml:"concurrent_polls"`
OptimalProcessing int `json:"optimal_processing" yaml:"optimal_processing"`
MaxOutstandingItems int `json:"max_outstanding_items" yaml:"max_outstanding_items"`
MaxItemProcessingTime time.Duration `json:"max_item_processing_time" yaml:"max_item_processing_time"`
MinRoundInterval time.Duration `json:"min_round_interval" yaml:"min_round_interval"`
ConcurrentPolls int `json:"concurrentPolls,omitempty" yaml:"concurrent_polls"`
OptimalProcessing int `json:"optimalProcessing,omitempty" yaml:"optimal_processing"`
MaxOutstandingItems int `json:"maxOutstandingItems,omitempty" yaml:"max_outstanding_items"`
MaxItemProcessingTime time.Duration `json:"maxItemProcessingTime,omitempty" yaml:"max_item_processing_time"`
MinRoundInterval time.Duration `json:"minRoundInterval,omitempty" yaml:"min_round_interval"`
// Fast-path voting configuration
FPC FPCConfig `json:"fpc" yaml:"fpc"`
+2 -1
View File
@@ -28,9 +28,10 @@ func Context(t testing.TB, chainID ids.ID) context.Context {
ctx := context.Background()
// Create IDs struct
// Use PrimaryNetworkID (empty ID) for subnet so chains get indexed
ids := consensus.IDs{
NetworkID: 10001,
SubnetID: ids.GenerateTestID(),
SubnetID: ids.Empty, // PrimaryNetworkID
ChainID: chainID,
NodeID: ids.GenerateTestNodeID(),
PublicKey: &bls.PublicKey{},
+120
View File
@@ -0,0 +1,120 @@
// Copyright (C) 2019-2024, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package coremock
import (
"context"
"reflect"
"go.uber.org/mock/gomock"
"github.com/luxfi/ids"
)
// MockAppSender is a mock of AppSender interface.
type MockAppSender struct {
ctrl *gomock.Controller
recorder *MockAppSenderMockRecorder
}
// MockAppSenderMockRecorder is the mock recorder for MockAppSender.
type MockAppSenderMockRecorder struct {
mock *MockAppSender
}
// NewMockAppSender creates a new mock instance.
func NewMockAppSender(ctrl *gomock.Controller) *MockAppSender {
mock := &MockAppSender{ctrl: ctrl}
mock.recorder = &MockAppSenderMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockAppSender) EXPECT() *MockAppSenderMockRecorder {
return m.recorder
}
// SendAppRequest mocks base method.
func (m *MockAppSender) SendAppRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, appRequestBytes []byte) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendAppRequest", ctx, nodeID, requestID, appRequestBytes)
ret0, _ := ret[0].(error)
return ret0
}
// SendAppRequest indicates an expected call of SendAppRequest.
func (mr *MockAppSenderMockRecorder) SendAppRequest(ctx, nodeID, requestID, appRequestBytes interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendAppRequest", reflect.TypeOf((*MockAppSender)(nil).SendAppRequest), ctx, nodeID, requestID, appRequestBytes)
}
// SendAppResponse mocks base method.
func (m *MockAppSender) SendAppResponse(ctx context.Context, nodeID ids.NodeID, requestID uint32, appResponseBytes []byte) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendAppResponse", ctx, nodeID, requestID, appResponseBytes)
ret0, _ := ret[0].(error)
return ret0
}
// SendAppResponse indicates an expected call of SendAppResponse.
func (mr *MockAppSenderMockRecorder) SendAppResponse(ctx, nodeID, requestID, appResponseBytes interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendAppResponse", reflect.TypeOf((*MockAppSender)(nil).SendAppResponse), ctx, nodeID, requestID, appResponseBytes)
}
// SendAppGossip mocks base method.
func (m *MockAppSender) SendAppGossip(ctx context.Context, appGossipBytes []byte) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendAppGossip", ctx, appGossipBytes)
ret0, _ := ret[0].(error)
return ret0
}
// SendAppGossip indicates an expected call of SendAppGossip.
func (mr *MockAppSenderMockRecorder) SendAppGossip(ctx, appGossipBytes interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendAppGossip", reflect.TypeOf((*MockAppSender)(nil).SendAppGossip), ctx, appGossipBytes)
}
// SendAppError mocks base method.
func (m *MockAppSender) SendAppError(ctx context.Context, nodeID ids.NodeID, requestID uint32, errorCode int32, errorMessage string) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendAppError", ctx, nodeID, requestID, errorCode, errorMessage)
ret0, _ := ret[0].(error)
return ret0
}
// SendAppError indicates an expected call of SendAppError.
func (mr *MockAppSenderMockRecorder) SendAppError(ctx, nodeID, requestID, errorCode, errorMessage interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendAppError", reflect.TypeOf((*MockAppSender)(nil).SendAppError), ctx, nodeID, requestID, errorCode, errorMessage)
}
// SendCrossChainAppRequest mocks base method.
func (m *MockAppSender) SendCrossChainAppRequest(ctx context.Context, chainID ids.ID, requestID uint32, appRequestBytes []byte) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCrossChainAppRequest", ctx, chainID, requestID, appRequestBytes)
ret0, _ := ret[0].(error)
return ret0
}
// SendCrossChainAppRequest indicates an expected call of SendCrossChainAppRequest.
func (mr *MockAppSenderMockRecorder) SendCrossChainAppRequest(ctx, chainID, requestID, appRequestBytes interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCrossChainAppRequest", reflect.TypeOf((*MockAppSender)(nil).SendCrossChainAppRequest), ctx, chainID, requestID, appRequestBytes)
}
// SendCrossChainAppResponse mocks base method.
func (m *MockAppSender) SendCrossChainAppResponse(ctx context.Context, chainID ids.ID, requestID uint32, appResponseBytes []byte) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCrossChainAppResponse", ctx, chainID, requestID, appResponseBytes)
ret0, _ := ret[0].(error)
return ret0
}
// SendCrossChainAppResponse indicates an expected call of SendCrossChainAppResponse.
func (mr *MockAppSenderMockRecorder) SendCrossChainAppResponse(ctx, chainID, requestID, appResponseBytes interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCrossChainAppResponse", reflect.TypeOf((*MockAppSender)(nil).SendCrossChainAppResponse), ctx, chainID, requestID, appResponseBytes)
}
+6 -15
View File
@@ -14,6 +14,9 @@ import (
"github.com/luxfi/ids"
)
// Ensure ChainVM implements block.ChainVM
var _ block.ChainVM = (*ChainVM)(nil)
// ChainVM is a mock implementation of block.ChainVM
type ChainVM struct {
T *testing.T
@@ -28,7 +31,7 @@ type ChainVM struct {
CantVerifyHeightIndex bool
CantGetBlockIDAtHeight bool
InitializeF func(context.Context, interface{}, interface{}, []byte, []byte, []byte, chan<- block.Message, []*block.Fx, block.AppSender) error
InitializeF func(context.Context, *block.ChainContext, block.DBManager, []byte, []byte, []byte, chan<- block.Message, []*block.Fx, block.AppSender) error
SetStateF func(context.Context, uint8) error
ShutdownF func(context.Context) error
BuildBlockF func(context.Context) (block.Block, error)
@@ -46,20 +49,8 @@ func NewChainVM(ctrl interface{}) *ChainVM {
return &ChainVM{}
}
// Initialize with no parameters for core.VM interface
func (vm *ChainVM) Initialize() error {
if vm.InitializeF != nil {
// Call with nil parameters for compatibility
return vm.InitializeF(nil, nil, nil, nil, nil, nil, nil, nil, nil)
}
if vm.CantInitialize && vm.T != nil {
vm.T.Fatal("unexpected Initialize")
}
return nil
}
// InitializeChain with full parameters for block.ChainVM interface
func (vm *ChainVM) InitializeChain(ctx context.Context, chainCtx interface{}, dbManager interface{}, genesisBytes []byte, upgradeBytes []byte, configBytes []byte, toEngine chan<- block.Message, fxs []*block.Fx, appSender block.AppSender) error {
// Initialize with correct signature for block.ChainVM interface
func (vm *ChainVM) Initialize(ctx context.Context, chainCtx *block.ChainContext, dbManager block.DBManager, genesisBytes []byte, upgradeBytes []byte, configBytes []byte, toEngine chan<- block.Message, fxs []*block.Fx, appSender block.AppSender) error {
if vm.InitializeF != nil {
return vm.InitializeF(ctx, chainCtx, dbManager, genesisBytes, upgradeBytes, configBytes, toEngine, fxs, appSender)
}
+2
View File
@@ -14,6 +14,8 @@ type Config struct {
// MinimumFailingDuration is the minimum amount of time a peer must be
// failing before we will consider benchlisting them
MinimumFailingDuration time.Duration `json:"minimumFailingDuration"`
// MaxPortion is the maximum portion of validators that can be benchlisted
MaxPortion float64 `json:"maxPortion"`
// Validators is the validator manager
Validators interface{} `json:"-"`
// Benchable is the object that can be benched
+8 -5
View File
@@ -7,10 +7,10 @@ import (
"context"
"time"
"github.com/luxfi/consensus/core"
"github.com/luxfi/ids"
"github.com/luxfi/log"
"github.com/luxfi/node/version"
"github.com/prometheus/client_golang/prometheus"
)
// ChainRouter routes messages between blockchain chains
@@ -22,7 +22,7 @@ type ChainRouter struct {
// Initialize initializes the ChainRouter
func (cr *ChainRouter) Initialize(
nodeID ids.NodeID,
log log.Logger,
logInterface interface{},
timeoutManager interface{},
closeTimeout time.Duration,
criticalChains interface{},
@@ -30,9 +30,11 @@ func (cr *ChainRouter) Initialize(
trackedSubnets interface{},
onFatal func(int),
healthConfig HealthConfig,
metricsRegisterer prometheus.Registerer,
metricsRegisterer interface{},
) error {
cr.log = log
if logger, ok := logInterface.(log.Logger); ok {
cr.log = logger
}
return nil
}
@@ -52,7 +54,7 @@ func (cr *ChainRouter) RemoveChain(chainID ids.ID) {
}
// HandleInbound handles an inbound message
func (cr *ChainRouter) HandleInbound(ctx context.Context, msg InboundMessage) {
func (cr *ChainRouter) HandleInbound(ctx context.Context, msg interface{}) {
// Implementation would go here
}
@@ -113,6 +115,7 @@ func (cr *ChainRouter) AppRequestFailed(
ctx context.Context,
nodeID ids.NodeID,
requestID uint32,
appErr *core.AppError,
) error {
return nil
}
+4
View File
@@ -19,4 +19,8 @@ type HealthConfig struct {
// MaxRunTimeHealthy is the maximum time the router can run before needing
// a health check
MaxRunTimeHealthy time.Duration `json:"maxRunTimeHealthy"`
// MaxRunTimeRequests is the maximum runtime for requests
MaxRunTimeRequests time.Duration `json:"maxRunTimeRequests"`
// MaxDropRateHalflife is the halflife for the drop rate calculation
MaxDropRateHalflife time.Duration `json:"maxDropRateHalflife"`
}
+1 -4
View File
@@ -5,7 +5,6 @@ import (
"time"
"github.com/luxfi/ids"
"github.com/luxfi/node/version"
)
// InboundMessage represents an inbound message
@@ -16,11 +15,9 @@ type InboundMessage interface {
// Router routes messages between chains
type Router interface {
ExternalHandler
AddChain(chainID ids.ID, handler interface{})
RemoveChain(chainID ids.ID)
HandleInbound(ctx context.Context, msg InboundMessage)
Connected(nodeID ids.NodeID, nodeVersion *version.Application, subnetID ids.ID)
Disconnected(nodeID ids.NodeID)
AppGossip(ctx context.Context, nodeID ids.NodeID, msg []byte) error
Initialize(
nodeID ids.NodeID,
-2
View File
@@ -1,6 +1,4 @@
package timeout
import "time"
// Timeout related types and functions will be in this file
// The Manager interface is defined in manager.go