From 716cc3663f6cd089bc0ac6c731122ac3a5d630d2 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Wed, 25 Mar 2020 19:14:20 -0500 Subject: [PATCH] don't throw error on duplicate key insert --- pkg/ipfs/dag_putters/btc_header.go | 7 ++++++- pkg/ipfs/dag_putters/btc_tx.go | 3 ++- pkg/ipfs/dag_putters/btc_tx_trie.go | 3 ++- pkg/ipfs/dag_putters/eth_header.go | 3 ++- pkg/ipfs/dag_putters/eth_receipt.go | 3 ++- pkg/ipfs/dag_putters/eth_receipt_trie.go | 3 ++- pkg/ipfs/dag_putters/eth_state.go | 3 ++- pkg/ipfs/dag_putters/eth_storage.go | 3 ++- pkg/ipfs/dag_putters/eth_tx.go | 3 ++- pkg/ipfs/dag_putters/eth_tx_trie.go | 3 ++- 10 files changed, 24 insertions(+), 10 deletions(-) diff --git a/pkg/ipfs/dag_putters/btc_header.go b/pkg/ipfs/dag_putters/btc_header.go index b35581b5..36aeba42 100644 --- a/pkg/ipfs/dag_putters/btc_header.go +++ b/pkg/ipfs/dag_putters/btc_header.go @@ -18,6 +18,7 @@ package dag_putters import ( "fmt" + "strings" node "github.com/ipfs/go-ipld-format" @@ -25,6 +26,10 @@ import ( "github.com/vulcanize/vulcanizedb/pkg/ipfs/ipld" ) +var ( + duplicateKeyErrorString = "pq: duplicate key value violates unique constraint" +) + type BtcHeaderDagPutter struct { adder *ipfs.IPFS } @@ -38,7 +43,7 @@ func (bhdp *BtcHeaderDagPutter) DagPut(n node.Node) (string, error) { if !ok { return "", fmt.Errorf("BtcHeaderDagPutter expected input type %T got %T", &ipld.BtcHeader{}, n) } - if err := bhdp.adder.Add(header); err != nil { + if err := bhdp.adder.Add(header); err != nil && !strings.Contains(err.Error(), duplicateKeyErrorString) { return "", err } return header.Cid().String(), nil diff --git a/pkg/ipfs/dag_putters/btc_tx.go b/pkg/ipfs/dag_putters/btc_tx.go index a958d781..52cc7bdd 100644 --- a/pkg/ipfs/dag_putters/btc_tx.go +++ b/pkg/ipfs/dag_putters/btc_tx.go @@ -18,6 +18,7 @@ package dag_putters import ( "fmt" + "strings" node "github.com/ipfs/go-ipld-format" @@ -38,7 +39,7 @@ func (etdp *BtcTxDagPutter) DagPut(n node.Node) (string, error) { if !ok { return "", fmt.Errorf("BtcTxDagPutter expected input type %T got %T", &ipld.BtcTx{}, n) } - if err := etdp.adder.Add(transaction); err != nil { + if err := etdp.adder.Add(transaction); err != nil && !strings.Contains(err.Error(), duplicateKeyErrorString) { return "", err } return transaction.Cid().String(), nil diff --git a/pkg/ipfs/dag_putters/btc_tx_trie.go b/pkg/ipfs/dag_putters/btc_tx_trie.go index 446e8d49..039e2d98 100644 --- a/pkg/ipfs/dag_putters/btc_tx_trie.go +++ b/pkg/ipfs/dag_putters/btc_tx_trie.go @@ -18,6 +18,7 @@ package dag_putters import ( "fmt" + "strings" node "github.com/ipfs/go-ipld-format" @@ -38,7 +39,7 @@ func (etdp *BtcTxTrieDagPutter) DagPut(n node.Node) (string, error) { if !ok { return "", fmt.Errorf("BtcTxTrieDagPutter expected input type %T got %T", &ipld.BtcTxTrie{}, n) } - if err := etdp.adder.Add(txTrieNode); err != nil { + if err := etdp.adder.Add(txTrieNode); err != nil && !strings.Contains(err.Error(), duplicateKeyErrorString) { return "", err } return txTrieNode.Cid().String(), nil diff --git a/pkg/ipfs/dag_putters/eth_header.go b/pkg/ipfs/dag_putters/eth_header.go index 3f38c650..630db6b3 100644 --- a/pkg/ipfs/dag_putters/eth_header.go +++ b/pkg/ipfs/dag_putters/eth_header.go @@ -18,6 +18,7 @@ package dag_putters import ( "fmt" + "strings" node "github.com/ipfs/go-ipld-format" @@ -38,7 +39,7 @@ func (bhdp *EthHeaderDagPutter) DagPut(n node.Node) (string, error) { if !ok { return "", fmt.Errorf("EthHeaderDagPutter expected input type %T got %T", &ipld.EthHeader{}, n) } - if err := bhdp.adder.Add(header); err != nil { + if err := bhdp.adder.Add(header); err != nil && !strings.Contains(err.Error(), duplicateKeyErrorString) { return "", err } return header.Cid().String(), nil diff --git a/pkg/ipfs/dag_putters/eth_receipt.go b/pkg/ipfs/dag_putters/eth_receipt.go index 0caa7f10..c099f8c8 100644 --- a/pkg/ipfs/dag_putters/eth_receipt.go +++ b/pkg/ipfs/dag_putters/eth_receipt.go @@ -18,6 +18,7 @@ package dag_putters import ( "fmt" + "strings" node "github.com/ipfs/go-ipld-format" @@ -38,7 +39,7 @@ func (erdp *EthReceiptDagPutter) DagPut(n node.Node) (string, error) { if !ok { return "", fmt.Errorf("EthReceiptDagPutter expected input type %T got type %T", &ipld.EthReceipt{}, n) } - if err := erdp.adder.Add(receipt); err != nil { + if err := erdp.adder.Add(receipt); err != nil && !strings.Contains(err.Error(), duplicateKeyErrorString) { return "", err } return receipt.Cid().String(), nil diff --git a/pkg/ipfs/dag_putters/eth_receipt_trie.go b/pkg/ipfs/dag_putters/eth_receipt_trie.go index 697e6ef2..6d982b3a 100644 --- a/pkg/ipfs/dag_putters/eth_receipt_trie.go +++ b/pkg/ipfs/dag_putters/eth_receipt_trie.go @@ -18,6 +18,7 @@ package dag_putters import ( "fmt" + "strings" node "github.com/ipfs/go-ipld-format" @@ -38,7 +39,7 @@ func (etdp *EthRctTrieDagPutter) DagPut(n node.Node) (string, error) { if !ok { return "", fmt.Errorf("EthRctTrieDagPutter expected input type %T got %T", &ipld.EthRctTrie{}, n) } - if err := etdp.adder.Add(rctTrieNode); err != nil { + if err := etdp.adder.Add(rctTrieNode); err != nil && !strings.Contains(err.Error(), duplicateKeyErrorString) { return "", err } return rctTrieNode.Cid().String(), nil diff --git a/pkg/ipfs/dag_putters/eth_state.go b/pkg/ipfs/dag_putters/eth_state.go index b435db28..9bfdbe44 100644 --- a/pkg/ipfs/dag_putters/eth_state.go +++ b/pkg/ipfs/dag_putters/eth_state.go @@ -18,6 +18,7 @@ package dag_putters import ( "fmt" + "strings" node "github.com/ipfs/go-ipld-format" @@ -38,7 +39,7 @@ func (erdp *EthStateDagPutter) DagPut(n node.Node) (string, error) { if !ok { return "", fmt.Errorf("EthStateDagPutter expected input type %T got %T", &ipld.EthStateTrie{}, n) } - if err := erdp.adder.Add(stateNode); err != nil { + if err := erdp.adder.Add(stateNode); err != nil && !strings.Contains(err.Error(), duplicateKeyErrorString) { return "", err } return stateNode.Cid().String(), nil diff --git a/pkg/ipfs/dag_putters/eth_storage.go b/pkg/ipfs/dag_putters/eth_storage.go index fce3fbd4..828de1f9 100644 --- a/pkg/ipfs/dag_putters/eth_storage.go +++ b/pkg/ipfs/dag_putters/eth_storage.go @@ -18,6 +18,7 @@ package dag_putters import ( "fmt" + "strings" node "github.com/ipfs/go-ipld-format" @@ -38,7 +39,7 @@ func (erdp *EthStorageDagPutter) DagPut(n node.Node) (string, error) { if !ok { return "", fmt.Errorf("EthStorageDagPutter expected input type %T got %T", &ipld.EthStorageTrie{}, n) } - if err := erdp.adder.Add(storageNode); err != nil { + if err := erdp.adder.Add(storageNode); err != nil && !strings.Contains(err.Error(), duplicateKeyErrorString) { return "", err } return storageNode.Cid().String(), nil diff --git a/pkg/ipfs/dag_putters/eth_tx.go b/pkg/ipfs/dag_putters/eth_tx.go index 51af68d9..906e1abf 100644 --- a/pkg/ipfs/dag_putters/eth_tx.go +++ b/pkg/ipfs/dag_putters/eth_tx.go @@ -18,6 +18,7 @@ package dag_putters import ( "fmt" + "strings" node "github.com/ipfs/go-ipld-format" @@ -38,7 +39,7 @@ func (etdp *EthTxsDagPutter) DagPut(n node.Node) (string, error) { if !ok { return "", fmt.Errorf("EthTxsDagPutter expected input type %T got %T", &ipld.EthTx{}, n) } - if err := etdp.adder.Add(transaction); err != nil { + if err := etdp.adder.Add(transaction); err != nil && !strings.Contains(err.Error(), duplicateKeyErrorString) { return "", err } return transaction.Cid().String(), nil diff --git a/pkg/ipfs/dag_putters/eth_tx_trie.go b/pkg/ipfs/dag_putters/eth_tx_trie.go index 12320214..f29478a2 100644 --- a/pkg/ipfs/dag_putters/eth_tx_trie.go +++ b/pkg/ipfs/dag_putters/eth_tx_trie.go @@ -18,6 +18,7 @@ package dag_putters import ( "fmt" + "strings" node "github.com/ipfs/go-ipld-format" @@ -38,7 +39,7 @@ func (etdp *EthTxTrieDagPutter) DagPut(n node.Node) (string, error) { if !ok { return "", fmt.Errorf("EthTxTrieDagPutter expected input type %T got %T", &ipld.EthTxTrie{}, n) } - if err := etdp.adder.Add(txTrieNode); err != nil { + if err := etdp.adder.Add(txTrieNode); err != nil && !strings.Contains(err.Error(), duplicateKeyErrorString) { return "", err } return txTrieNode.Cid().String(), nil