Skip to content

Commit

Permalink
Clean up code in relay
Browse files Browse the repository at this point in the history
  • Loading branch information
kwon528 committed Jul 31, 2023
1 parent f20e315 commit 0eba41b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
18 changes: 9 additions & 9 deletions chain/ethbr/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var (
txSizeLimit = int(math.Ceil(txMaxDataSize / (1 + txOverheadScale)))
)

type Queue struct {
type queue struct {
values []*relayMessageTx
}

Expand All @@ -57,12 +57,12 @@ type relayMessageTx struct {
txHash []byte
}

func NewQueue() *Queue {
queue := &Queue{}
func newQueue() *queue {
queue := &queue{}
return queue
}

func (q *Queue) enqueue(id string, txHash []byte) error {
func (q *queue) enqueue(id string, txHash []byte) error {
if MaxQueueSize <= len(q.values) {
return fmt.Errorf("queue full")
}
Expand All @@ -74,7 +74,7 @@ func (q *Queue) enqueue(id string, txHash []byte) error {
return nil
}

func (q *Queue) dequeue(id string) {
func (q *queue) dequeue(id string) {
for i, rm := range q.values {
if rm.id == id {
q.values = q.values[i+1:]
Expand All @@ -83,11 +83,11 @@ func (q *Queue) dequeue(id string) {
}
}

func (q *Queue) isEmpty() bool {
func (q *queue) isEmpty() bool {
return len(q.values) == 0
}

func (q *Queue) len() int {
func (q *queue) len() int {
return len(q.values)
}

Expand All @@ -102,7 +102,7 @@ type sender struct {
bmc *binding.BMC
rr chan *btpTypes.RelayResult
isFoundOffsetBySeq bool
queue *Queue
queue *queue
}

func newSender(srcAddr btpTypes.BtpAddress, dstCfg link.ChainConfig, w btpTypes.Wallet, endpoint string, opt map[string]interface{}, l log.Logger) btpTypes.Sender {
Expand All @@ -112,7 +112,7 @@ func newSender(srcAddr btpTypes.BtpAddress, dstCfg link.ChainConfig, w btpTypes.
w: w,
l: l,
rr: make(chan *btpTypes.RelayResult),
queue: NewQueue(),
queue: newQueue(),
}

b, err := json.Marshal(opt)
Expand Down
18 changes: 9 additions & 9 deletions chain/icon/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var (
txSizeLimit = int(math.Ceil(txMaxDataSize / (1 + txOverheadScale)))
)

type Queue struct {
type queue struct {
values []*relayMessageTx
}

Expand All @@ -57,12 +57,12 @@ type relayMessageTx struct {
txHash []byte
}

func NewQueue() *Queue {
queue := &Queue{}
func newQueue() *queue {
queue := &queue{}
return queue
}

func (q *Queue) enqueue(id string, txHash []byte) error {
func (q *queue) enqueue(id string, txHash []byte) error {
if MaxQueueSize <= len(q.values) {
return fmt.Errorf("queue full")
}
Expand All @@ -74,7 +74,7 @@ func (q *Queue) enqueue(id string, txHash []byte) error {
return nil
}

func (q *Queue) dequeue(id string) {
func (q *queue) dequeue(id string) {
for i, rm := range q.values {
if rm.id == id {
q.values = q.values[i+1:]
Expand All @@ -83,11 +83,11 @@ func (q *Queue) dequeue(id string) {
}
}

func (q *Queue) isEmpty() bool {
func (q *queue) isEmpty() bool {
return len(q.values) == 0
}

func (q *Queue) len() int {
func (q *queue) len() int {
return len(q.values)
}

Expand All @@ -102,7 +102,7 @@ type sender struct {
}
rr chan *types.RelayResult
isFoundOffsetBySeq bool
queue *Queue
queue *queue
}

func NewSender(srcAddr types.BtpAddress, dstCfg link.ChainConfig, w types.Wallet, endpoint string, opt map[string]interface{}, l log.Logger) types.Sender {
Expand All @@ -112,7 +112,7 @@ func NewSender(srcAddr types.BtpAddress, dstCfg link.ChainConfig, w types.Wallet
w: w,
l: l,
rr: make(chan *types.RelayResult),
queue: NewQueue(),
queue: newQueue(),
}
b, err := json.Marshal(opt)
if err != nil {
Expand Down
12 changes: 7 additions & 5 deletions common/link/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ func (l *Link) buildRelayMessage() error {
func (l *Link) sendRelayMessage() error {
for _, rm := range l.rms {
if rm.sendingStatus == false {
l.l.Debugf("SendRelayMessage (bls height:%d, bls txSeq:%d, bls rxSeq:%d)",
rm.bls.Verifier.Height, rm.bls.TxSeq, rm.bls.RxSeq)
l.l.Debugf("SendRelayMessage (bls height:%d, bls rxSeq:%d)",
rm.bls.Verifier.Height, rm.bls.RxSeq)
_, err := l.s.Relay(rm)
if err != nil {
if errors.InvalidStateError.Equals(err) {
Expand Down Expand Up @@ -261,8 +261,8 @@ func (l *Link) appendRelayMessage() error {

rm.sendingStatus = false
l.rms = append(l.rms, rm)
l.l.Debugf("AppendRelayMessage (bls height:%d, bls txSeq:%d, bls rxSeq:%d)",
rm.bls.Verifier.Height, rm.bls.TxSeq, rm.bls.RxSeq)
l.l.Debugf("AppendRelayMessage (bls height:%d, bls rxSeq:%d)",
rm.bls.Verifier.Height, rm.bls.RxSeq)
}

l.rmi.rmis = l.rmi.rmis[:0]
Expand Down Expand Up @@ -564,7 +564,9 @@ func (l *Link) result(rr *types.RelayResult) error {
}
case errors.BMVRevertInvalidBlockWitnessOld:
//TODO Error handling required on Finalized
l.updateBlockProof(rr.Id)
if err := l.updateBlockProof(rr.Id); err != nil {
return err
}
default:
l.l.Panicf("fail to GetResult RelayMessage ID:%v ErrorCoder:%+v",
rr.Id, rr.Err)
Expand Down

0 comments on commit 0eba41b

Please sign in to comment.