Commit 4cefbdee authored by Son of Odin's avatar Son of Odin 💬

Merge branch 'bifrost-seq-incr' into 'master'

[bugfix] increment seqnum only after successful broadcast

See merge request !684
parents 1836d50a 9738db9e
Pipeline #129437492 failed with stages
in 27 minutes and 49 seconds
......@@ -368,9 +368,6 @@ func (b *Binance) SignTx(tx stypes.TxOutItem, height int64) ([]byte, error) {
return nil, nil
}
// increment sequence number
b.accts.SeqInc(tx.VaultPubKey, currentHeight)
hexTx := []byte(hex.EncodeToString(rawBz))
return hexTx, nil
}
......@@ -482,7 +479,7 @@ func (b *Binance) GetAccount(addr string) (common.Account, error) {
}
// broadcastTx is to broadcast the tx to binance chain
func (b *Binance) BroadcastTx(hexTx []byte) error {
func (b *Binance) BroadcastTx(tx stypes.TxOutItem, hexTx []byte) error {
u, err := url.Parse(b.RPCHost)
if err != nil {
log.Error().Msgf("Error parsing rpc (%s): %s", b.RPCHost, err)
......@@ -534,5 +531,8 @@ func (b *Binance) BroadcastTx(hexTx []byte) error {
}
}
// increment sequence number
b.accts.SeqInc(tx.VaultPubKey)
return nil
}
......@@ -214,7 +214,7 @@ func (s *BinancechainSuite) TestSignTx(c *C) {
c.Assert(err, IsNil)
c.Assert(r, NotNil)
err = b2.BroadcastTx(r)
err = b2.BroadcastTx(out, r)
c.Assert(err, IsNil)
}
......
......@@ -50,12 +50,11 @@ func (b *BinanceMetaDataStore) Set(pk common.PubKey, meta BinanceMetadata) {
b.accts[pk] = meta
}
func (b *BinanceMetaDataStore) SeqInc(pk common.PubKey, blockHeight int64) {
func (b *BinanceMetaDataStore) SeqInc(pk common.PubKey) {
b.lock.Lock()
defer b.lock.Unlock()
if meta, ok := b.accts[pk]; ok {
meta.SeqNumber += 1
meta.BlockHeight = blockHeight
b.accts[pk] = meta
}
}
......@@ -33,9 +33,8 @@ func (s *MetadataSuite) TestMetaData(c *C) {
c.Check(meta.AccountNumber, Equals, int64(0))
c.Check(meta.SeqNumber, Equals, int64(0))
store.SeqInc(pk, 12)
store.SeqInc(pk)
meta = store.Get(pk)
c.Check(meta.AccountNumber, Equals, int64(1))
c.Check(meta.SeqNumber, Equals, int64(3))
c.Check(meta.BlockHeight, Equals, int64(12))
}
......@@ -23,7 +23,7 @@ import (
type ChainClient interface {
SignTx(tx stypes.TxOutItem, height int64) ([]byte, error)
BroadcastTx(tx []byte) error
BroadcastTx(_ stypes.TxOutItem, _ []byte) error
GetHeight() (int64, error)
GetAddress(poolPubKey common.PubKey) string
GetAccount(addr string) (common.Account, error)
......
......@@ -18,10 +18,10 @@ type DummyChain struct{}
func (DummyChain) SignTx(tx stypes.TxOutItem, height int64) ([]byte, error) {
return nil, kaboom
}
func (DummyChain) BroadcastTx(tx []byte) error { return kaboom }
func (DummyChain) CheckIsTestNet() (string, bool) { return "", false }
func (DummyChain) GetHeight() (int64, error) { return 0, kaboom }
func (DummyChain) GetAddress(poolPubKey common.PubKey) string { return "" }
func (DummyChain) BroadcastTx(_ stypes.TxOutItem, tx []byte) error { return kaboom }
func (DummyChain) CheckIsTestNet() (string, bool) { return "", false }
func (DummyChain) GetHeight() (int64, error) { return 0, kaboom }
func (DummyChain) GetAddress(poolPubKey common.PubKey) string { return "" }
func (DummyChain) GetAccount(addr string) (common.Account, error) {
return common.Account{}, kaboom
}
......
......@@ -366,7 +366,7 @@ func (s *Signer) signAndBroadcast(item TxOutStoreItem) error {
return nil
}
if err := chain.BroadcastTx(signedTx); err != nil {
if err := chain.BroadcastTx(tx, signedTx); err != nil {
s.logger.Error().Err(err).Msg("fail to broadcast tx to chain")
return err
}
......
......@@ -248,7 +248,7 @@ func (b *MockChainClient) ValidateMetadata(inter interface{}) bool {
return true
}
func (b *MockChainClient) BroadcastTx(tx []byte) error {
func (b *MockChainClient) BroadcastTx(_ stypes.TxOutItem, tx []byte) error {
return nil
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment