-
Notifications
You must be signed in to change notification settings - Fork 699
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix P-chain validator set lookup race condition
- Loading branch information
1 parent
b81b936
commit 0a00887
Showing
10 changed files
with
180 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,7 @@ func (c *Client) AppRequest( | |
c.router.lock.Lock() | ||
defer c.router.lock.Unlock() | ||
|
||
appRequestBytes = c.prefixMessage(appRequestBytes) | ||
appRequestBytes = PrefixMessage(c.handlerPrefix, appRequestBytes) | ||
for nodeID := range nodeIDs { | ||
requestID := c.router.requestID | ||
if _, ok := c.router.pendingAppRequests[requestID]; ok { | ||
|
@@ -112,7 +112,7 @@ func (c *Client) AppGossip( | |
) error { | ||
return c.sender.SendAppGossip( | ||
ctx, | ||
c.prefixMessage(appGossipBytes), | ||
PrefixMessage(c.handlerPrefix, appGossipBytes), | ||
) | ||
} | ||
|
||
|
@@ -125,7 +125,7 @@ func (c *Client) AppGossipSpecific( | |
return c.sender.SendAppGossipSpecific( | ||
ctx, | ||
nodeIDs, | ||
c.prefixMessage(appGossipBytes), | ||
PrefixMessage(c.handlerPrefix, appGossipBytes), | ||
) | ||
} | ||
|
||
|
@@ -153,7 +153,7 @@ func (c *Client) CrossChainAppRequest( | |
ctx, | ||
chainID, | ||
requestID, | ||
c.prefixMessage(appRequestBytes), | ||
PrefixMessage(c.handlerPrefix, appRequestBytes), | ||
); err != nil { | ||
return err | ||
} | ||
|
@@ -167,15 +167,14 @@ func (c *Client) CrossChainAppRequest( | |
return nil | ||
} | ||
|
||
// prefixMessage prefixes the original message with the handler identifier | ||
// corresponding to this client. | ||
// PrefixMessage prefixes the original message with the protocol identifier. | ||
// | ||
// Only gossip and request messages need to be prefixed. | ||
// Response messages don't need to be prefixed because request ids are tracked | ||
// which map to the expected response handler. | ||
func (c *Client) prefixMessage(src []byte) []byte { | ||
messageBytes := make([]byte, len(c.handlerPrefix)+len(src)) | ||
copy(messageBytes, c.handlerPrefix) | ||
copy(messageBytes[len(c.handlerPrefix):], src) | ||
func PrefixMessage(prefix, msg []byte) []byte { | ||
messageBytes := make([]byte, len(prefix)+len(msg)) | ||
Check failure Code scanning / CodeQL Size computation for allocation may overflow High
This operation, which is used in an
allocation Error loading related location Loading potentially large value Error loading related location Loading This operation, which is used in an allocation Error loading related location Loading potentially large value Error loading related location Loading This operation, which is used in an allocation Error loading related location Loading This operation, which is used in an allocation Error loading related location Loading This operation, which is used in an allocation Error loading related location Loading This operation, which is used in an allocation Error loading related location Loading This operation, which is used in an allocation Error loading related location Loading This operation, which is used in an allocation Error loading related location Loading This operation, which is used in an allocation Error loading related location Loading This operation, which is used in an allocation Error loading related location Loading |
||
copy(messageBytes, prefix) | ||
copy(messageBytes[len(prefix):], msg) | ||
return messageBytes | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package gossip | ||
|
||
import ( | ||
"google.golang.org/protobuf/proto" | ||
|
||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/proto/pb/sdk" | ||
"github.com/ava-labs/avalanchego/utils/bloom" | ||
) | ||
|
||
func MarshalAppRequest(filter, salt []byte) ([]byte, error) { | ||
request := &sdk.PullGossipRequest{ | ||
Filter: filter, | ||
Salt: salt, | ||
} | ||
return proto.Marshal(request) | ||
} | ||
|
||
func ParseAppRequest(bytes []byte) (*bloom.ReadFilter, ids.ID, error) { | ||
request := &sdk.PullGossipRequest{} | ||
if err := proto.Unmarshal(bytes, request); err != nil { | ||
return nil, ids.Empty, err | ||
} | ||
|
||
salt, err := ids.ToID(request.Salt) | ||
if err != nil { | ||
return nil, ids.Empty, err | ||
} | ||
|
||
filter, err := bloom.Parse(request.Filter) | ||
return filter, salt, err | ||
} | ||
|
||
func MarshalAppResponse(gossip [][]byte) ([]byte, error) { | ||
return proto.Marshal(&sdk.PullGossipResponse{ | ||
Gossip: gossip, | ||
}) | ||
} | ||
|
||
func ParseAppResponse(bytes []byte) ([][]byte, error) { | ||
response := &sdk.PullGossipResponse{} | ||
err := proto.Unmarshal(bytes, response) | ||
return response.Gossip, err | ||
} | ||
|
||
func MarshalAppGossip(gossip [][]byte) ([]byte, error) { | ||
return proto.Marshal(&sdk.PushGossip{ | ||
Gossip: gossip, | ||
}) | ||
} | ||
|
||
func ParseAppGossip(bytes []byte) ([][]byte, error) { | ||
msg := &sdk.PushGossip{} | ||
err := proto.Unmarshal(bytes, msg) | ||
return msg.Gossip, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.