[#338] ir: Drop notaryless code from netmap
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
fb708b3a2d
commit
656fd7f376
5 changed files with 136 additions and 322 deletions
|
@ -71,7 +71,6 @@ func (s *Server) initNetmapProcessor(cfg *viper.Viper,
|
||||||
addrvalidator.New(),
|
addrvalidator.New(),
|
||||||
locodeValidator,
|
locodeValidator,
|
||||||
),
|
),
|
||||||
NotaryDisabled: s.sideNotaryConfig.disabled,
|
|
||||||
|
|
||||||
NodeStateSettings: netSettings,
|
NodeStateSettings: netSettings,
|
||||||
})
|
})
|
||||||
|
|
|
@ -31,7 +31,6 @@ func TestNewEpochTick(t *testing.T) {
|
||||||
nc := &testNetmapClient{}
|
nc := &testNetmapClient{}
|
||||||
|
|
||||||
proc, err := newTestProc(t, func(p *Params) {
|
proc, err := newTestProc(t, func(p *Params) {
|
||||||
p.NotaryDisabled = true
|
|
||||||
p.CleanupEnabled = true
|
p.CleanupEnabled = true
|
||||||
p.EpochState = es
|
p.EpochState = es
|
||||||
p.NetmapClient = nc
|
p.NetmapClient = nc
|
||||||
|
@ -80,7 +79,6 @@ func TestNewEpoch(t *testing.T) {
|
||||||
eh := &testEventHandler{}
|
eh := &testEventHandler{}
|
||||||
|
|
||||||
proc, err := newTestProc(t, func(p *Params) {
|
proc, err := newTestProc(t, func(p *Params) {
|
||||||
p.NotaryDisabled = true
|
|
||||||
p.NotaryDepositHandler = eh.Handle
|
p.NotaryDepositHandler = eh.Handle
|
||||||
p.AlphabetSyncHandler = eh.Handle
|
p.AlphabetSyncHandler = eh.Handle
|
||||||
p.NetmapClient = nc
|
p.NetmapClient = nc
|
||||||
|
@ -119,276 +117,139 @@ func TestNewEpoch(t *testing.T) {
|
||||||
func TestAddPeer(t *testing.T) {
|
func TestAddPeer(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
t.Run("with notary", func(t *testing.T) {
|
nc := &testNetmapClient{
|
||||||
t.Parallel()
|
contractAddress: util.Uint160{47},
|
||||||
nc := &testNetmapClient{
|
}
|
||||||
contractAddress: util.Uint160{47},
|
|
||||||
}
|
|
||||||
|
|
||||||
proc, err := newTestProc(t, func(p *Params) {
|
proc, err := newTestProc(t, func(p *Params) {
|
||||||
p.NotaryDisabled = true
|
p.NetmapClient = nc
|
||||||
p.NetmapClient = nc
|
|
||||||
})
|
|
||||||
|
|
||||||
require.NoError(t, err, "failed to create processor")
|
|
||||||
|
|
||||||
var node netmap.NodeInfo
|
|
||||||
key, err := keys.NewPublicKeyFromString("038c862959e56b43e20f79187c4fe9e0bc7c8c66c1603e6cf0ec7f87ab6b08dc35")
|
|
||||||
require.NoError(t, err, "failed to parse key1")
|
|
||||||
node.SetPublicKey(key.Bytes())
|
|
||||||
|
|
||||||
ev := netmapEvent.AddPeer{
|
|
||||||
NodeBytes: node.Marshal(),
|
|
||||||
Request: &payload.P2PNotaryRequest{
|
|
||||||
MainTransaction: &transaction.Transaction{
|
|
||||||
Nonce: 100,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
proc.handleAddPeer(ev)
|
|
||||||
|
|
||||||
for proc.pool.Running() > 0 {
|
|
||||||
time.Sleep(10 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
require.EqualValues(t, []notaryInvoke{
|
|
||||||
{
|
|
||||||
contract: nc.contractAddress,
|
|
||||||
fee: 0,
|
|
||||||
nonce: ev.Request.MainTransaction.Nonce,
|
|
||||||
vub: nil,
|
|
||||||
method: "addPeerIR",
|
|
||||||
args: []any{ev.Node()},
|
|
||||||
},
|
|
||||||
}, nc.notaryInvokes, "invalid notary invokes")
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("without notary", func(t *testing.T) {
|
require.NoError(t, err, "failed to create processor")
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
nc := &testNetmapClient{
|
var node netmap.NodeInfo
|
||||||
contractAddress: util.Uint160{47},
|
key, err := keys.NewPublicKeyFromString("038c862959e56b43e20f79187c4fe9e0bc7c8c66c1603e6cf0ec7f87ab6b08dc35")
|
||||||
}
|
require.NoError(t, err, "failed to parse key")
|
||||||
|
node.SetPublicKey(key.Bytes())
|
||||||
|
|
||||||
proc, err := newTestProc(t, func(p *Params) {
|
ev := netmapEvent.AddPeer{
|
||||||
p.NotaryDisabled = true
|
NodeBytes: node.Marshal(),
|
||||||
p.NetmapClient = nc
|
Request: &payload.P2PNotaryRequest{
|
||||||
})
|
MainTransaction: &transaction.Transaction{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
proc.handleAddPeer(ev)
|
||||||
|
|
||||||
require.NoError(t, err, "failed to create processor")
|
for proc.pool.Running() > 0 {
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
var node netmap.NodeInfo
|
require.EqualValues(t, []notaryInvoke{
|
||||||
key, err := keys.NewPublicKeyFromString("038c862959e56b43e20f79187c4fe9e0bc7c8c66c1603e6cf0ec7f87ab6b08dc35")
|
{
|
||||||
require.NoError(t, err, "failed to parse key")
|
contract: nc.contractAddress,
|
||||||
node.SetPublicKey(key.Bytes())
|
fee: 0,
|
||||||
|
nonce: ev.NotaryRequest().MainTransaction.Nonce,
|
||||||
ev := netmapEvent.AddPeer{
|
vub: nil,
|
||||||
NodeBytes: node.Marshal(),
|
method: "addPeerIR",
|
||||||
}
|
args: []any{node.Marshal()},
|
||||||
proc.handleAddPeer(ev)
|
},
|
||||||
|
}, nc.notaryInvokes, "invalid notary invokes")
|
||||||
for proc.pool.Running() > 0 {
|
|
||||||
time.Sleep(10 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
var addPeerExp netmapclient.AddPeerPrm
|
|
||||||
addPeerExp.SetNodeInfo(node)
|
|
||||||
require.EqualValues(t, []netmapclient.AddPeerPrm{addPeerExp}, nc.addPeers, "invalid peers")
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateState(t *testing.T) {
|
func TestUpdateState(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
t.Run("with notary", func(t *testing.T) {
|
ns := &testNodeStateSettings{
|
||||||
t.Parallel()
|
maintAllowed: true,
|
||||||
ns := &testNodeStateSettings{
|
}
|
||||||
maintAllowed: true,
|
nc := &testNetmapClient{}
|
||||||
}
|
|
||||||
nc := &testNetmapClient{}
|
|
||||||
|
|
||||||
proc, err := newTestProc(t, func(p *Params) {
|
proc, err := newTestProc(t, func(p *Params) {
|
||||||
p.NotaryDisabled = true
|
p.NetmapClient = nc
|
||||||
p.NodeStateSettings = ns
|
p.NodeStateSettings = ns
|
||||||
p.NetmapClient = nc
|
|
||||||
})
|
|
||||||
|
|
||||||
require.NoError(t, err, "failed to create processor")
|
|
||||||
|
|
||||||
key, err := keys.NewPublicKeyFromString("038c862959e56b43e20f79187c4fe9e0bc7c8c66c1603e6cf0ec7f87ab6b08dc35")
|
|
||||||
require.NoError(t, err, "failed to parse key")
|
|
||||||
|
|
||||||
ev := netmapEvent.UpdatePeer{
|
|
||||||
State: netmapContract.NodeStateOnline,
|
|
||||||
PubKey: key,
|
|
||||||
Request: &payload.P2PNotaryRequest{
|
|
||||||
MainTransaction: &transaction.Transaction{
|
|
||||||
Nonce: 100,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
proc.handleUpdateState(ev)
|
|
||||||
|
|
||||||
for proc.pool.Running() > 0 {
|
|
||||||
time.Sleep(10 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
require.EqualValues(t, []*transaction.Transaction{
|
|
||||||
ev.Request.MainTransaction,
|
|
||||||
}, nc.invokedTxs, "invalid invoked transactions")
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("without notary", func(t *testing.T) {
|
require.NoError(t, err, "failed to create processor")
|
||||||
t.Parallel()
|
|
||||||
ns := &testNodeStateSettings{
|
|
||||||
maintAllowed: true,
|
|
||||||
}
|
|
||||||
nc := &testNetmapClient{}
|
|
||||||
|
|
||||||
proc, err := newTestProc(t, func(p *Params) {
|
key, err := keys.NewPublicKeyFromString("038c862959e56b43e20f79187c4fe9e0bc7c8c66c1603e6cf0ec7f87ab6b08dc35")
|
||||||
p.NetmapClient = nc
|
require.NoError(t, err, "failed to parse key")
|
||||||
p.NodeStateSettings = ns
|
|
||||||
})
|
|
||||||
|
|
||||||
require.NoError(t, err, "failed to create processor")
|
ev := netmapEvent.UpdatePeer{
|
||||||
|
State: netmapContract.NodeStateOnline,
|
||||||
|
PubKey: key,
|
||||||
|
Request: &payload.P2PNotaryRequest{
|
||||||
|
MainTransaction: &transaction.Transaction{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
proc.handleUpdateState(ev)
|
||||||
|
|
||||||
key, err := keys.NewPublicKeyFromString("038c862959e56b43e20f79187c4fe9e0bc7c8c66c1603e6cf0ec7f87ab6b08dc35")
|
for proc.pool.Running() > 0 {
|
||||||
require.NoError(t, err, "failed to parse key")
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
ev := netmapEvent.UpdatePeer{
|
require.EqualValues(t, []*transaction.Transaction{ev.Request.MainTransaction}, nc.invokedTxs, "invalid transactions")
|
||||||
State: netmapContract.NodeStateOnline,
|
|
||||||
PubKey: key,
|
|
||||||
}
|
|
||||||
proc.handleUpdateState(ev)
|
|
||||||
|
|
||||||
for proc.pool.Running() > 0 {
|
|
||||||
time.Sleep(10 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
var expUpdPeer netmapclient.UpdatePeerPrm
|
|
||||||
expUpdPeer.SetMaintenance()
|
|
||||||
expUpdPeer.SetOnline()
|
|
||||||
expUpdPeer.SetKey(ev.PubKey.Bytes())
|
|
||||||
|
|
||||||
require.EqualValues(t, []netmapclient.UpdatePeerPrm{expUpdPeer}, nc.peerStateUpdates, "invalid peer state updates")
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCleanupTick(t *testing.T) {
|
func TestCleanupTick(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
t.Run("notary disabled", func(t *testing.T) {
|
nc := &testNetmapClient{
|
||||||
t.Parallel()
|
contractAddress: util.Uint160{111},
|
||||||
|
}
|
||||||
nc := &testNetmapClient{}
|
proc, err := newTestProc(t,
|
||||||
|
func(p *Params) {
|
||||||
proc, err := newTestProc(t, func(p *Params) {
|
|
||||||
p.NetmapClient = nc
|
p.NetmapClient = nc
|
||||||
p.NotaryDisabled = true
|
|
||||||
p.CleanupEnabled = true
|
p.CleanupEnabled = true
|
||||||
})
|
},
|
||||||
|
)
|
||||||
|
|
||||||
require.NoError(t, err, "failed to create processor")
|
require.NoError(t, err, "failed to create processor")
|
||||||
|
|
||||||
key1Str := "038c862959e56b43e20f79187c4fe9e0bc7c8c66c1603e6cf0ec7f87ab6b08dc35"
|
key1Str := "038c862959e56b43e20f79187c4fe9e0bc7c8c66c1603e6cf0ec7f87ab6b08dc35"
|
||||||
proc.netmapSnapshot.lastAccess[key1Str] = epochStampWithNodeInfo{
|
proc.netmapSnapshot.lastAccess[key1Str] = epochStampWithNodeInfo{
|
||||||
epochStamp: epochStamp{
|
epochStamp: epochStamp{
|
||||||
epoch: 95,
|
epoch: 95,
|
||||||
removeFlag: false,
|
removeFlag: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
key2Str := "02ac920cd7df0b61b289072e6b946e2da4e1a31b9ab1c621bb475e30fa4ab102c3"
|
key2Str := "02ac920cd7df0b61b289072e6b946e2da4e1a31b9ab1c621bb475e30fa4ab102c3"
|
||||||
proc.netmapSnapshot.lastAccess[key2Str] = epochStampWithNodeInfo{
|
proc.netmapSnapshot.lastAccess[key2Str] = epochStampWithNodeInfo{
|
||||||
epochStamp: epochStamp{
|
epochStamp: epochStamp{
|
||||||
epoch: 98,
|
epoch: 98,
|
||||||
removeFlag: false,
|
removeFlag: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
ev := netmapCleanupTick{
|
ev := netmapCleanupTick{
|
||||||
epoch: 100,
|
epoch: 100,
|
||||||
txHash: util.Uint256{123},
|
txHash: util.Uint256{123},
|
||||||
}
|
}
|
||||||
|
|
||||||
proc.handleCleanupTick(ev)
|
proc.handleCleanupTick(ev)
|
||||||
|
|
||||||
for proc.pool.Running() > 0 {
|
for proc.pool.Running() > 0 {
|
||||||
time.Sleep(10 * time.Millisecond)
|
time.Sleep(10 * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
keyExp, err := keys.NewPublicKeyFromString(key1Str)
|
keyExp, err := keys.NewPublicKeyFromString(key1Str)
|
||||||
require.NoError(t, err, "failed to parse expired key")
|
require.NoError(t, err, "failed to parse expired key")
|
||||||
|
|
||||||
updExp := netmapclient.UpdatePeerPrm{}
|
updExp := netmapclient.UpdatePeerPrm{}
|
||||||
updExp.SetKey(keyExp.Bytes())
|
updExp.SetKey(keyExp.Bytes())
|
||||||
updExp.SetHash(ev.TxHash())
|
updExp.SetHash(ev.TxHash())
|
||||||
|
|
||||||
require.EqualValues(t, []netmapclient.UpdatePeerPrm{updExp}, nc.peerStateUpdates, "invalid peer updates")
|
require.EqualValues(t, []notaryInvoke{
|
||||||
require.True(t, proc.netmapSnapshot.lastAccess[key1Str].removeFlag, "invalid expired removed flag")
|
{
|
||||||
require.False(t, proc.netmapSnapshot.lastAccess[key2Str].removeFlag, "invalid non expired removed flag")
|
contract: nc.contractAddress,
|
||||||
})
|
fee: 0,
|
||||||
|
nonce: uint32(ev.epoch),
|
||||||
t.Run("notary enabled", func(t *testing.T) {
|
vub: nil,
|
||||||
t.Parallel()
|
method: "updateStateIR",
|
||||||
|
args: []any{int64(v2netmap.Offline), keyExp.Bytes()},
|
||||||
nc := &testNetmapClient{
|
},
|
||||||
contractAddress: util.Uint160{111},
|
}, nc.notaryInvokes, "invalid notary invokes")
|
||||||
}
|
require.True(t, proc.netmapSnapshot.lastAccess[key1Str].removeFlag, "invalid expired removed flag")
|
||||||
proc, err := newTestProc(t,
|
require.False(t, proc.netmapSnapshot.lastAccess[key2Str].removeFlag, "invalid non expired removed flag")
|
||||||
func(p *Params) {
|
|
||||||
p.NetmapClient = nc
|
|
||||||
p.CleanupEnabled = true
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
require.NoError(t, err, "failed to create processor")
|
|
||||||
|
|
||||||
key1Str := "038c862959e56b43e20f79187c4fe9e0bc7c8c66c1603e6cf0ec7f87ab6b08dc35"
|
|
||||||
proc.netmapSnapshot.lastAccess[key1Str] = epochStampWithNodeInfo{
|
|
||||||
epochStamp: epochStamp{
|
|
||||||
epoch: 95,
|
|
||||||
removeFlag: false,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
key2Str := "02ac920cd7df0b61b289072e6b946e2da4e1a31b9ab1c621bb475e30fa4ab102c3"
|
|
||||||
proc.netmapSnapshot.lastAccess[key2Str] = epochStampWithNodeInfo{
|
|
||||||
epochStamp: epochStamp{
|
|
||||||
epoch: 98,
|
|
||||||
removeFlag: false,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
ev := netmapCleanupTick{
|
|
||||||
epoch: 100,
|
|
||||||
txHash: util.Uint256{123},
|
|
||||||
}
|
|
||||||
|
|
||||||
proc.handleCleanupTick(ev)
|
|
||||||
|
|
||||||
for proc.pool.Running() > 0 {
|
|
||||||
time.Sleep(10 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
keyExp, err := keys.NewPublicKeyFromString(key1Str)
|
|
||||||
require.NoError(t, err, "failed to parse expired key")
|
|
||||||
|
|
||||||
updExp := netmapclient.UpdatePeerPrm{}
|
|
||||||
updExp.SetKey(keyExp.Bytes())
|
|
||||||
updExp.SetHash(ev.TxHash())
|
|
||||||
|
|
||||||
require.EqualValues(t, []notaryInvoke{
|
|
||||||
{
|
|
||||||
contract: nc.contractAddress,
|
|
||||||
fee: 0,
|
|
||||||
nonce: uint32(ev.epoch),
|
|
||||||
vub: nil,
|
|
||||||
method: "updateStateIR",
|
|
||||||
args: []any{int64(v2netmap.Offline), keyExp.Bytes()},
|
|
||||||
},
|
|
||||||
}, nc.notaryInvokes, "invalid notary invokes")
|
|
||||||
require.True(t, proc.netmapSnapshot.lastAccess[key1Str].removeFlag, "invalid expired removed flag")
|
|
||||||
require.False(t, proc.netmapSnapshot.lastAccess[key2Str].removeFlag, "invalid non expired removed flag")
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestProc(t *testing.T, nonDefault func(p *Params)) (*Processor, error) {
|
func newTestProc(t *testing.T, nonDefault func(p *Params)) (*Processor, error) {
|
||||||
|
@ -407,7 +268,6 @@ func newTestProc(t *testing.T, nonDefault func(p *Params)) (*Processor, error) {
|
||||||
PoolSize: 1,
|
PoolSize: 1,
|
||||||
CleanupEnabled: false,
|
CleanupEnabled: false,
|
||||||
CleanupThreshold: 3,
|
CleanupThreshold: 3,
|
||||||
NotaryDisabled: false,
|
|
||||||
NodeStateSettings: ns,
|
NodeStateSettings: ns,
|
||||||
NodeValidator: &testValidator{},
|
NodeValidator: &testValidator{},
|
||||||
EpochState: es,
|
EpochState: es,
|
||||||
|
@ -500,17 +360,11 @@ type testNetmapClient struct {
|
||||||
netmap *netmap.NetMap
|
netmap *netmap.NetMap
|
||||||
txHeights map[util.Uint256]uint32
|
txHeights map[util.Uint256]uint32
|
||||||
|
|
||||||
peerStateUpdates []netmapclient.UpdatePeerPrm
|
notaryInvokes []notaryInvoke
|
||||||
notaryInvokes []notaryInvoke
|
newEpochs []uint64
|
||||||
newEpochs []uint64
|
invokedTxs []*transaction.Transaction
|
||||||
addPeers []netmapclient.AddPeerPrm
|
|
||||||
invokedTxs []*transaction.Transaction
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *testNetmapClient) UpdatePeerState(p netmapclient.UpdatePeerPrm) error {
|
|
||||||
c.peerStateUpdates = append(c.peerStateUpdates, p)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (c *testNetmapClient) MorphNotaryInvoke(contract util.Uint160, fee fixedn.Fixed8, nonce uint32, vub *uint32, method string, args ...any) error {
|
func (c *testNetmapClient) MorphNotaryInvoke(contract util.Uint160, fee fixedn.Fixed8, nonce uint32, vub *uint32, method string, args ...any) error {
|
||||||
c.notaryInvokes = append(c.notaryInvokes, notaryInvoke{
|
c.notaryInvokes = append(c.notaryInvokes, notaryInvoke{
|
||||||
contract: contract,
|
contract: contract,
|
||||||
|
@ -522,32 +376,35 @@ func (c *testNetmapClient) MorphNotaryInvoke(contract util.Uint160, fee fixedn.F
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *testNetmapClient) ContractAddress() util.Uint160 {
|
func (c *testNetmapClient) ContractAddress() util.Uint160 {
|
||||||
return c.contractAddress
|
return c.contractAddress
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *testNetmapClient) EpochDuration() (uint64, error) {
|
func (c *testNetmapClient) EpochDuration() (uint64, error) {
|
||||||
return c.epochDuration, nil
|
return c.epochDuration, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *testNetmapClient) MorphTxHeight(h util.Uint256) (uint32, error) {
|
func (c *testNetmapClient) MorphTxHeight(h util.Uint256) (uint32, error) {
|
||||||
if res, found := c.txHeights[h]; found {
|
if res, found := c.txHeights[h]; found {
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
return 0, fmt.Errorf("not found")
|
return 0, fmt.Errorf("not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *testNetmapClient) NetMap() (*netmap.NetMap, error) {
|
func (c *testNetmapClient) NetMap() (*netmap.NetMap, error) {
|
||||||
return c.netmap, nil
|
return c.netmap, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *testNetmapClient) NewEpoch(epoch uint64, force bool) error {
|
func (c *testNetmapClient) NewEpoch(epoch uint64, force bool) error {
|
||||||
c.newEpochs = append(c.newEpochs, epoch)
|
c.newEpochs = append(c.newEpochs, epoch)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *testNetmapClient) MorphIsValidScript(script []byte, signers []transaction.Signer) (valid bool, err error) {
|
func (c *testNetmapClient) MorphIsValidScript(script []byte, signers []transaction.Signer) (valid bool, err error) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
func (c *testNetmapClient) AddPeer(p netmapclient.AddPeerPrm) error {
|
|
||||||
c.addPeers = append(c.addPeers, p)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (c *testNetmapClient) MorphNotarySignAndInvokeTX(mainTx *transaction.Transaction) error {
|
func (c *testNetmapClient) MorphNotarySignAndInvokeTX(mainTx *transaction.Transaction) error {
|
||||||
c.invokedTxs = append(c.invokedTxs, mainTx)
|
c.invokedTxs = append(c.invokedTxs, mainTx)
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -3,7 +3,6 @@ package netmap
|
||||||
import (
|
import (
|
||||||
v2netmap "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap"
|
v2netmap "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
||||||
netmapclient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/netmap"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
@ -31,23 +30,14 @@ func (np *Processor) processNetmapCleanupTick(ev netmapCleanupTick) {
|
||||||
// See https://github.com/nspcc-dev/frostfs-contract/issues/225
|
// See https://github.com/nspcc-dev/frostfs-contract/issues/225
|
||||||
const methodUpdateStateNotary = "updateStateIR"
|
const methodUpdateStateNotary = "updateStateIR"
|
||||||
|
|
||||||
if np.notaryDisabled {
|
err = np.netmapClient.MorphNotaryInvoke(
|
||||||
prm := netmapclient.UpdatePeerPrm{}
|
np.netmapClient.ContractAddress(),
|
||||||
|
0,
|
||||||
prm.SetKey(key.Bytes())
|
uint32(ev.epoch),
|
||||||
prm.SetHash(ev.TxHash())
|
nil,
|
||||||
|
methodUpdateStateNotary,
|
||||||
err = np.netmapClient.UpdatePeerState(prm)
|
int64(v2netmap.Offline), key.Bytes(),
|
||||||
} else {
|
)
|
||||||
err = np.netmapClient.MorphNotaryInvoke(
|
|
||||||
np.netmapClient.ContractAddress(),
|
|
||||||
0,
|
|
||||||
uint32(ev.epoch),
|
|
||||||
nil,
|
|
||||||
methodUpdateStateNotary,
|
|
||||||
int64(v2netmap.Offline), key.Bytes(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
np.log.Error(logs.NetmapCantInvokeNetmapUpdateState, zap.Error(err))
|
np.log.Error(logs.NetmapCantInvokeNetmapUpdateState, zap.Error(err))
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,16 +19,14 @@ func (np *Processor) processAddPeer(ev netmapEvent.AddPeer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if notary transaction is valid, see #976
|
// check if notary transaction is valid, see #976
|
||||||
if originalRequest := ev.NotaryRequest(); originalRequest != nil {
|
tx := ev.NotaryRequest().MainTransaction
|
||||||
tx := originalRequest.MainTransaction
|
ok, err := np.netmapClient.MorphIsValidScript(tx.Script, tx.Signers)
|
||||||
ok, err := np.netmapClient.MorphIsValidScript(tx.Script, tx.Signers)
|
if err != nil || !ok {
|
||||||
if err != nil || !ok {
|
np.log.Warn(logs.NetmapNonhaltNotaryTransaction,
|
||||||
np.log.Warn(logs.NetmapNonhaltNotaryTransaction,
|
zap.String("method", "netmap.AddPeer"),
|
||||||
zap.String("method", "netmap.AddPeer"),
|
zap.String("hash", tx.Hash().StringLE()),
|
||||||
zap.String("hash", tx.Hash().StringLE()),
|
zap.Error(err))
|
||||||
zap.Error(err))
|
return
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// unmarshal node info
|
// unmarshal node info
|
||||||
|
@ -40,7 +38,7 @@ func (np *Processor) processAddPeer(ev netmapEvent.AddPeer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate and update node info
|
// validate and update node info
|
||||||
err := np.nodeValidator.VerifyAndUpdate(&nodeInfo)
|
err = np.nodeValidator.VerifyAndUpdate(&nodeInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
np.log.Warn(logs.NetmapCouldNotVerifyAndUpdateInformationAboutNetworkMapCandidate,
|
np.log.Warn(logs.NetmapCouldNotVerifyAndUpdateInformationAboutNetworkMapCandidate,
|
||||||
zap.String("error", err.Error()),
|
zap.String("error", err.Error()),
|
||||||
|
@ -71,20 +69,15 @@ func (np *Processor) processAddPeer(ev netmapEvent.AddPeer) {
|
||||||
// See https://github.com/nspcc-dev/frostfs-contract/issues/154.
|
// See https://github.com/nspcc-dev/frostfs-contract/issues/154.
|
||||||
const methodAddPeerNotary = "addPeerIR"
|
const methodAddPeerNotary = "addPeerIR"
|
||||||
|
|
||||||
if nr := ev.NotaryRequest(); nr != nil {
|
// create new notary request with the original nonce
|
||||||
// create new notary request with the original nonce
|
err = np.netmapClient.MorphNotaryInvoke(
|
||||||
err = np.netmapClient.MorphNotaryInvoke(
|
np.netmapClient.ContractAddress(),
|
||||||
np.netmapClient.ContractAddress(),
|
0,
|
||||||
0,
|
ev.NotaryRequest().MainTransaction.Nonce,
|
||||||
nr.MainTransaction.Nonce,
|
nil,
|
||||||
nil,
|
methodAddPeerNotary,
|
||||||
methodAddPeerNotary,
|
nodeInfoBinary,
|
||||||
nodeInfoBinary,
|
)
|
||||||
)
|
|
||||||
} else {
|
|
||||||
// notification event case
|
|
||||||
err = np.netmapClient.AddPeer(prm)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
np.log.Error(logs.NetmapCantInvokeNetmapAddPeer, zap.Error(err))
|
np.log.Error(logs.NetmapCantInvokeNetmapAddPeer, zap.Error(err))
|
||||||
|
@ -116,23 +109,7 @@ func (np *Processor) processUpdatePeer(ev netmapEvent.UpdatePeer) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if nr := ev.NotaryRequest(); nr != nil {
|
if err = np.netmapClient.MorphNotarySignAndInvokeTX(ev.NotaryRequest().MainTransaction); err != nil {
|
||||||
err = np.netmapClient.MorphNotarySignAndInvokeTX(nr.MainTransaction)
|
|
||||||
} else {
|
|
||||||
prm := netmapclient.UpdatePeerPrm{}
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case ev.Online():
|
|
||||||
prm.SetOnline()
|
|
||||||
case ev.Maintenance():
|
|
||||||
prm.SetMaintenance()
|
|
||||||
}
|
|
||||||
|
|
||||||
prm.SetKey(ev.PublicKey().Bytes())
|
|
||||||
|
|
||||||
err = np.netmapClient.UpdatePeerState(prm)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
np.log.Error(logs.NetmapCantInvokeNetmapUpdatePeer, zap.Error(err))
|
np.log.Error(logs.NetmapCantInvokeNetmapUpdatePeer, zap.Error(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/netmap/nodevalidation/state"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/netmap/nodevalidation/state"
|
||||||
cntClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/container"
|
cntClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/container"
|
||||||
netmapclient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/netmap"
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
|
||||||
netmapEvent "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event/netmap"
|
netmapEvent "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event/netmap"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
||||||
|
@ -55,7 +54,6 @@ type (
|
||||||
}
|
}
|
||||||
|
|
||||||
Client interface {
|
Client interface {
|
||||||
UpdatePeerState(p netmapclient.UpdatePeerPrm) error
|
|
||||||
MorphNotaryInvoke(contract util.Uint160, fee fixedn.Fixed8, nonce uint32, vub *uint32, method string, args ...any) error
|
MorphNotaryInvoke(contract util.Uint160, fee fixedn.Fixed8, nonce uint32, vub *uint32, method string, args ...any) error
|
||||||
ContractAddress() util.Uint160
|
ContractAddress() util.Uint160
|
||||||
EpochDuration() (uint64, error)
|
EpochDuration() (uint64, error)
|
||||||
|
@ -63,7 +61,6 @@ type (
|
||||||
NetMap() (*netmap.NetMap, error)
|
NetMap() (*netmap.NetMap, error)
|
||||||
NewEpoch(epoch uint64, force bool) error
|
NewEpoch(epoch uint64, force bool) error
|
||||||
MorphIsValidScript(script []byte, signers []transaction.Signer) (valid bool, err error)
|
MorphIsValidScript(script []byte, signers []transaction.Signer) (valid bool, err error)
|
||||||
AddPeer(p netmapclient.AddPeerPrm) error
|
|
||||||
MorphNotarySignAndInvokeTX(mainTx *transaction.Transaction) error
|
MorphNotarySignAndInvokeTX(mainTx *transaction.Transaction) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,8 +87,6 @@ type (
|
||||||
|
|
||||||
nodeValidator NodeValidator
|
nodeValidator NodeValidator
|
||||||
|
|
||||||
notaryDisabled bool
|
|
||||||
|
|
||||||
nodeStateSettings state.NetworkSettings
|
nodeStateSettings state.NetworkSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,8 +107,6 @@ type (
|
||||||
|
|
||||||
NodeValidator NodeValidator
|
NodeValidator NodeValidator
|
||||||
|
|
||||||
NotaryDisabled bool
|
|
||||||
|
|
||||||
NodeStateSettings state.NetworkSettings
|
NodeStateSettings state.NetworkSettings
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -168,8 +161,6 @@ func New(p *Params) (*Processor, error) {
|
||||||
|
|
||||||
nodeValidator: p.NodeValidator,
|
nodeValidator: p.NodeValidator,
|
||||||
|
|
||||||
notaryDisabled: p.NotaryDisabled,
|
|
||||||
|
|
||||||
nodeStateSettings: p.NodeStateSettings,
|
nodeStateSettings: p.NodeStateSettings,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue