Skip to content

Commit

Permalink
Merge pull request #62 from bloXroute-Labs/v2.129.28
Browse files Browse the repository at this point in the history
Publish release v2.129.28
  • Loading branch information
i-Alex authored Sep 19, 2024
2 parents 8597962 + a465e52 commit 83d2b8d
Show file tree
Hide file tree
Showing 52 changed files with 2,802 additions and 857 deletions.
8 changes: 7 additions & 1 deletion blockchain/beacon/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ func (c *APIClient) subscribeToEvents(eventsURL string, handler func(msg *sse.Ev
if errors.Is(err, context.Canceled) {
return
}
disconnectEventErr := c.bridge.SendBlockchainConnectionStatus(blockchain.ConnectionStatus{PeerEndpoint: c.nodeEndpoint, IsConnected: false})
if disconnectEventErr != nil {
log.Errorf("was not able to set node status to not connected, err: %v", err)
} else {
c.isConnected = false
}

if err != nil {
c.log.Errorf("failed to subscribe to head events: %v", err)
Expand Down Expand Up @@ -456,7 +462,7 @@ func (c *APIClient) blockHeadEventHandler() func(msg *sse.Event) {

if !c.isConnected {
// if we were not able to set the node to connected, we will try again next block
if err := c.bridge.SendConnectedEvent(c.nodeEndpoint); err != nil {
if err := c.bridge.SendBlockchainConnectionStatus(blockchain.ConnectionStatus{PeerEndpoint: c.nodeEndpoint, IsConnected: true}); err != nil {
log.Errorf("was not able to set node status to connected, err: %v", err)
} else {
c.isConnected = true
Expand Down
20 changes: 0 additions & 20 deletions blockchain/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ type Bridge interface {

SendDisconnectEvent(endpoint types.NodeEndpoint) error
ReceiveDisconnectEvent() <-chan types.NodeEndpoint

SendConnectedEvent(endpoint types.NodeEndpoint) error
ReceiveConnectEvent() <-chan types.NodeEndpoint
}

// Errors
Expand Down Expand Up @@ -179,7 +176,6 @@ type BxBridge struct {
nodeConnectionCheckResponse chan types.NodeEndpoint
blockchainConnectionStatus chan ConnectionStatus
disconnectEvent chan types.NodeEndpoint
connectEvent chan types.NodeEndpoint
}

// NewBxBridge returns a BxBridge instance
Expand All @@ -206,7 +202,6 @@ func NewBxBridge(converter Converter, withBeacon bool) Bridge {
nodeConnectionCheckResponse: make(chan types.NodeEndpoint, statusBacklog),
blockchainConnectionStatus: make(chan ConnectionStatus, transactionBacklog),
disconnectEvent: make(chan types.NodeEndpoint, statusBacklog),
connectEvent: make(chan types.NodeEndpoint, statusBacklog),
Converter: converter,
}
}
Expand Down Expand Up @@ -518,18 +513,3 @@ func (b BxBridge) SendDisconnectEvent(endpoint types.NodeEndpoint) error {
func (b BxBridge) ReceiveDisconnectEvent() <-chan types.NodeEndpoint {
return b.disconnectEvent
}

// SendConnectedEvent send connected event
func (b BxBridge) SendConnectedEvent(endpoint types.NodeEndpoint) error {
select {
case b.connectEvent <- endpoint:
return nil
default:
return ErrChannelFull
}
}

// ReceiveConnectEvent receive connected event
func (b BxBridge) ReceiveConnectEvent() <-chan types.NodeEndpoint {
return b.connectEvent
}
8 changes: 0 additions & 8 deletions blockchain/noop_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,3 @@ func (n NoOpBxBridge) SendDisconnectEvent(endpoint types.NodeEndpoint) error { r
func (n NoOpBxBridge) ReceiveDisconnectEvent() <-chan types.NodeEndpoint {
return make(chan types.NodeEndpoint)
}

// SendConnectedEvent is a no-op
func (n NoOpBxBridge) SendConnectedEvent(endpoint types.NodeEndpoint) error { return nil }

// ReceiveConnectEvent is a no-op
func (n NoOpBxBridge) ReceiveConnectEvent() <-chan types.NodeEndpoint {
return make(<-chan types.NodeEndpoint)
}
11 changes: 0 additions & 11 deletions bxmessage/bdn_performance_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,17 +327,6 @@ func (bs *BdnPerformanceStats) getOrCreateNodeStats(node types.NodeEndpoint) *Bd
return stats
}

// SetNodeToConnected setting the node to connected, if not found in the map, we add it
func (bs *BdnPerformanceStats) SetNodeToConnected(node types.NodeEndpoint) {
stats, found := bs.nodeStats[node.IPPort()]
if !found {
stats = &BdnPerformanceStatsData{IsBeacon: node.IsBeacon, IsConnected: true}
bs.nodeStats[node.IPPort()] = stats
} else {
stats.IsConnected = true
}
}

// Pack serializes a BdnPerformanceStats into a buffer for sending
func (bs *BdnPerformanceStats) Pack(protocol Protocol) ([]byte, error) {
bs.lock.Lock()
Expand Down
20 changes: 7 additions & 13 deletions bxmessage/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ const (
SolutionsUnsubscriptionType = "solsunsub"
BeaconMessageType = "beaconmsg"
GetIntentSolutionsType = "getintsol"
QuotesType = "quotes"
QuotesSubscriptionType = "quotessub"
QuotesUnsubscriptionType = "quotesunsub"
)

// SenderLen is the byte length of sender
Expand All @@ -101,7 +104,10 @@ const EmptyProtocol = 0
const MinProtocol = NextValidatorMultipleProtocol

// CurrentProtocol tracks the most recent version of the bloxroute wire protocol
const CurrentProtocol = SolutionSenderAddressProtocol
const CurrentProtocol = QuotesProtocol

// QuotesProtocol is the minimum protocol version that supports intent quotes
const QuotesProtocol = 50

// SolutionSenderAddressProtocol is the minimum protocol version that supports solution sender address
// in the intent solution broadcast message
Expand Down Expand Up @@ -166,18 +172,6 @@ var NullByteAccountID = bytes.Repeat([]byte("\x00"), AccountIDLen)

var clock utils.Clock = utils.RealClock{}

// UUIDv4Len is the byte length of UUID V4
const UUIDv4Len = 16

// ETHAddressLen is the byte length of ETH Address
const ETHAddressLen = 20

// Keccak256HashLen is the byte length of Keccak256Hash
const Keccak256HashLen = 32

// ECDSASignatureLen is the byte length of ECDSASignature in Ethereum ecosystem
const ECDSASignatureLen = 65

// IsConnectedLen is the byte of IsConnectedLen byte
const IsConnectedLen = 1

Expand Down
8 changes: 4 additions & 4 deletions bxmessage/get_intent_solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ func NewGetIntentSolutions(intentID, dAppOrSenderAddress string, hash, signature
func (s *GetIntentSolutions) Pack(_ Protocol) ([]byte, error) {
bufLen, err := calcPackSize(
HeaderLen,
UUIDv4Len,
ETHAddressLen,
Keccak256HashLen,
ECDSASignatureLen,
types.UUIDv4Len,
types.ETHAddressLen,
types.Keccak256HashLen,
types.ECDSASignatureLen,
ControlByteLen,
)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions bxmessage/intent.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ func (i *Intent) Pack(protocol Protocol) ([]byte, error) {

bufLen, err := calcPackSize(
HeaderLen,
UUIDv4Len,
ETHAddressLen,
ETHAddressLen,
Keccak256HashLen,
ECDSASignatureLen,
types.UUIDv4Len,
types.ETHAddressLen,
types.ETHAddressLen,
types.Keccak256HashLen,
types.ECDSASignatureLen,
ShortTimestampLen,
i.Intent,
ControlByteLen,
Expand Down
14 changes: 7 additions & 7 deletions bxmessage/intent_solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ func (i *IntentSolution) Unpack(buf []byte, protocol Protocol) error {
func (i *IntentSolution) size(protocol Protocol) (uint32, error) {
size, err := calcPackSize(
HeaderLen,
UUIDv4Len,
ETHAddressLen,
UUIDv4Len,
types.UUIDv4Len,
types.ETHAddressLen,
types.UUIDv4Len,
i.Solution,
Keccak256HashLen,
ECDSASignatureLen,
types.Keccak256HashLen,
types.ECDSASignatureLen,
ShortTimestampLen,
ControlByteLen,
)
Expand All @@ -229,11 +229,11 @@ func (i *IntentSolution) size(protocol Protocol) (uint32, error) {
}

if protocol >= IntentSolutionProtocol {
size += ETHAddressLen // DappAddress
size += types.ETHAddressLen // DappAddress
}

if protocol >= SolutionSenderAddressProtocol {
size += ETHAddressLen // SenderAddress
size += types.ETHAddressLen // SenderAddress
}

return size, nil
Expand Down
17 changes: 11 additions & 6 deletions bxmessage/intent_solutions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/google/uuid"
"github.com/bloXroute-Labs/gateway/v2/utils/intent"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -13,7 +13,7 @@ func TestIntentSolutions_Unpack(t *testing.T) {
solutions := make([]IntentSolution, 5)

for i := 0; i < 5; i++ {
solutions[i] = createTestIntentSolution()
solutions[i] = createTestIntentSolution(t)
}

intentSolutions := NewIntentSolutions(solutions)
Expand All @@ -33,17 +33,22 @@ func TestIntentSolutions_Unpack(t *testing.T) {
}
}

func createTestIntentSolution() IntentSolution {
func createTestIntentSolution(t *testing.T) IntentSolution {
r := genIntentsRequest()
solution := []byte("this is test :(")
intentID, err := intent.GenerateSolutionID("test", []byte("test"))
require.NoError(t, err)
id, err := intent.GenerateSolutionID(intentID, solution)
require.NoError(t, err)

return IntentSolution{
Header: Header{
msgType: IntentSolutionType,
},
ID: uuid.New().String(),
ID: id,
SolverAddress: r.SolverAddress,
IntentID: uuid.New().String(),
Solution: []byte("this is test :("),
IntentID: intentID,
Solution: solution,
Hash: r.Hash,
Signature: r.Signature,
Timestamp: time.Now(),
Expand Down
9 changes: 6 additions & 3 deletions bxmessage/intent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@ import (
"time"

gateway "github.com/bloXroute-Labs/gateway/v2/protobuf"
id "github.com/bloXroute-Labs/gateway/v2/utils/intent"
"github.com/ethereum/go-ethereum/crypto"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
)

func TestIntent_Unpack(t *testing.T) {
r := genIntentsRequest()

intentByte := []byte("testing intent")
intentID, err := id.GenerateIntentID(r.SolverAddress, intentByte)
require.NoError(t, err)
intent := Intent{
Header: Header{
msgType: "intent",
},
ID: uuid.New().String(),
ID: intentID,
DAppAddress: r.SolverAddress,
SenderAddress: "0xb794F5eA0ba39494cE839613fffBA74279579268",
Hash: r.Hash,
Signature: r.Signature,
Timestamp: time.Now(),
Intent: []byte("testing intent"),
Intent: intentByte,
}

bytes, err := intent.Pack(CurrentProtocol)
Expand Down
8 changes: 5 additions & 3 deletions bxmessage/intents_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package bxmessage

import (
"fmt"

"github.com/bloXroute-Labs/gateway/v2/types"
)

// UnpackIntentsSubscription unpacks IntentsSubscription bxmessage from bytes
Expand Down Expand Up @@ -41,9 +43,9 @@ func (i *IntentsSubscription) Pack(protocol Protocol) ([]byte, error) {

bufLen, err := calcPackSize(
HeaderLen,
ETHAddressLen,
Keccak256HashLen,
ECDSASignatureLen,
types.ETHAddressLen,
types.Keccak256HashLen,
types.ECDSASignatureLen,
ControlByteLen,
)
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions bxmessage/intents_unsubscription.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package bxmessage

import "fmt"
import (
"fmt"

"github.com/bloXroute-Labs/gateway/v2/types"
)

// UnpackIntentsUnsubscription unpacks IntentsUnsubscription bxmessage from bytes
func UnpackIntentsUnsubscription(b []byte, protocol Protocol) (*IntentsUnsubscription, error) {
Expand Down Expand Up @@ -35,7 +39,7 @@ func (i *IntentsUnsubscription) Pack(protocol Protocol) ([]byte, error) {

bufLen, err := calcPackSize(
HeaderLen,
ETHAddressLen,
types.ETHAddressLen,
ControlByteLen,
)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions bxmessage/mev_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (m MEVBundle) size(protocol Protocol, txs [][]byte) uint32 {
size += BroadcastHeaderLen // Broadcast header + Control Byte
size += types.UInt16Len // Method size-prefix
size += uint32(len(m.Method)) // Method content
size += UUIDv4Len // UUID
size += types.UUIDv4Len // UUID
size += types.UInt64Len // BlockNumber
size += types.UInt32Len // MinTimestamp
size += types.UInt32Len // MaxTimestamp
Expand Down Expand Up @@ -274,7 +274,7 @@ func (m MEVBundle) Pack(protocol Protocol) ([]byte, error) {

copy(buf[offset:], uuidBytes[:])
}
offset += UUIDv4Len
offset += types.UUIDv4Len

// Transactions
binary.LittleEndian.PutUint16(buf[offset:], uint16(len(decodedTxs)))
Expand Down Expand Up @@ -453,17 +453,17 @@ func (m *MEVBundle) Unpack(data []byte, protocol Protocol) error {
offset += int(methodLen)

// UUID
if err := checkBufSize(&data, offset, UUIDv4Len); err != nil {
if err := checkBufSize(&data, offset, types.UUIDv4Len); err != nil {
return err
}
if uuidBytes := data[offset : offset+UUIDv4Len]; !bytes.Equal(uuidBytes, emptyUUID) {
if uuidBytes := data[offset : offset+types.UUIDv4Len]; !bytes.Equal(uuidBytes, emptyUUID) {
uuidRaw, err := uuid.FromBytes(uuidBytes)
if err != nil {
return fmt.Errorf("failed to parse uuid from bytes, %v", err)
}
m.UUID = uuidRaw.String()
}
offset += UUIDv4Len
offset += types.UUIDv4Len

// Transactions
if err := checkBufSize(&data, offset, types.UInt16Len); err != nil {
Expand Down
Loading

0 comments on commit 83d2b8d

Please sign in to comment.