diff --git a/node/pkg/common/obsvReqSendC.go b/node/pkg/common/obsvReqSendC.go index 6d50d1eb8..298193695 100644 --- a/node/pkg/common/obsvReqSendC.go +++ b/node/pkg/common/obsvReqSendC.go @@ -1,19 +1,20 @@ package common import ( - "fmt" + "errors" gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1" ) const ObsvReqChannelSize = 50 -const ObsvReqChannelFullError = "channel is full" -func PostObservationRequest(obsvReqSendC chan *gossipv1.ObservationRequest, req *gossipv1.ObservationRequest) error { - if len(obsvReqSendC) >= cap(obsvReqSendC) { - return fmt.Errorf(ObsvReqChannelFullError) +var ErrChanFull = errors.New("channel is full") + +func PostObservationRequest(obsvReqSendC chan<- *gossipv1.ObservationRequest, req *gossipv1.ObservationRequest) error { + select { + case obsvReqSendC <- req: + return nil + default: + return ErrChanFull } - - obsvReqSendC <- req - return nil } diff --git a/node/pkg/common/obsvReqSendC_test.go b/node/pkg/common/obsvReqSendC_test.go index d2a08a971..8fe7f222e 100644 --- a/node/pkg/common/obsvReqSendC_test.go +++ b/node/pkg/common/obsvReqSendC_test.go @@ -30,8 +30,7 @@ func TestObsvReqSendLimitEnforced(t *testing.T) { ChainId: uint32(vaa.ChainIDSolana), } err := PostObservationRequest(obsvReqSendC, req) - assert.NotNil(t, err) - assert.Equal(t, ObsvReqChannelFullError, err.Error()) + assert.ErrorIs(t, err, ErrChanFull) done = true }()