-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
client/asset/eth: less provider check spam #2159
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,6 @@ import ( | |
"decred.org/dcrdex/dex" | ||
"decred.org/dcrdex/dex/networks/erc20" | ||
dexeth "decred.org/dcrdex/dex/networks/eth" | ||
"github.com/decred/slog" | ||
"github.com/ethereum/go-ethereum" | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/common" | ||
|
@@ -697,7 +696,7 @@ func createAndCheckProviders(ctx context.Context, walletDir string, endpoints [] | |
if len(providers) != len(unknownEndpoints) { | ||
return providersErr(providers) | ||
} | ||
if err := checkProvidersCompliance(ctx, providers, net, log); err != nil { | ||
if err := checkProvidersCompliance(ctx, providers, net, dex.Disabled /* logger is for testing only */); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could do this when calling EDIT: There are some logs up there we probably would want. |
||
return err | ||
} | ||
} | ||
|
@@ -1400,7 +1399,9 @@ type rpcTest struct { | |
|
||
// newCompatibilityTests returns a list of RPC tests to run to determine API | ||
// compatibility. | ||
func newCompatibilityTests(cb bind.ContractBackend, net dex.Network, log slog.Logger) []*rpcTest { | ||
func newCompatibilityTests(cb bind.ContractBackend, net dex.Network, log dex.Logger) []*rpcTest { | ||
// NOTE: The logger is intended for use the execution of the compatibility | ||
// tests, and it will generally be dex.Disabled in production. | ||
var ( | ||
// Vitalik's address from https://twitter.com/VitalikButerin/status/1050126908589887488 | ||
mainnetAddr = common.HexToAddress("0xab5801a7d398351b8be11c439e05c5b3259aec9b") | ||
|
@@ -1440,15 +1441,15 @@ func newCompatibilityTests(cb bind.ContractBackend, net dex.Network, log slog.Lo | |
readIt := func(path string) string { | ||
b, err := os.ReadFile(path) | ||
if err != nil { | ||
log.Errorf("Problem reading simnet testing file: %v", err) | ||
panic(fmt.Sprintf("Problem reading simnet testing file %q: %v", path, err)) | ||
} | ||
return strings.TrimRight(string(b), "\r\n") | ||
return strings.TrimSpace(string(b)) // mainly the trailing "\r\n" | ||
} | ||
usdc = common.HexToAddress(readIt(tContractFile)) | ||
txHash = common.HexToHash(readIt(tTxHashFile)) | ||
blockHash = common.HexToHash(readIt(tBlockHashFile)) | ||
default: | ||
log.Errorf("Unknown net %v in compatibility tests. Testing data not initiated.", net) | ||
default: // caller should have checked though | ||
panic(fmt.Sprintf("Unknown net %v in compatibility tests. Testing data not initiated.", net)) | ||
Comment on lines
+1451
to
+1452
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the product code, there are probably 30 places it would panic before getting here anyway. It's virtually impossible to get an unrecognized |
||
} | ||
|
||
return []*rpcTest{ | ||
|
@@ -1487,7 +1488,7 @@ func newCompatibilityTests(cb bind.ContractBackend, net dex.Network, log slog.Lo | |
if err != nil { | ||
return err | ||
} | ||
log.Info("#### Retreived tip cap:", tipCap) | ||
log.Debugf("#### Retrieved tip cap: %d gwei", dexeth.WeiToGwei(tipCap)) | ||
return nil | ||
}, | ||
}, | ||
|
@@ -1498,7 +1499,7 @@ func newCompatibilityTests(cb bind.ContractBackend, net dex.Network, log slog.Lo | |
if err != nil { | ||
return err | ||
} | ||
log.Infof("#### Balance retrieved: %.9f", float64(dexeth.WeiToGwei(bal))/1e9) | ||
log.Debugf("#### Balance retrieved: %.9f", float64(dexeth.WeiToGwei(bal))/1e9) | ||
return nil | ||
}, | ||
}, | ||
|
@@ -1509,7 +1510,7 @@ func newCompatibilityTests(cb bind.ContractBackend, net dex.Network, log slog.Lo | |
if err != nil { | ||
return err | ||
} | ||
log.Infof("#### %d bytes of USDC contract retrieved", len(code)) | ||
log.Debugf("#### %d bytes of USDC contract retrieved", len(code)) | ||
return nil | ||
}, | ||
}, | ||
|
@@ -1530,7 +1531,7 @@ func newCompatibilityTests(cb bind.ContractBackend, net dex.Network, log slog.Lo | |
// I guess we would need to unpack the results. I don't really | ||
// know how to interpret these, but I'm really just looking for | ||
// a request error. | ||
log.Info("#### USDC balanceOf result:", bal, "wei") | ||
log.Debug("#### USDC balanceOf result:", dexeth.WeiToGwei(bal), "gwei") | ||
return nil | ||
}, | ||
}, | ||
|
@@ -1541,18 +1542,7 @@ func newCompatibilityTests(cb bind.ContractBackend, net dex.Network, log slog.Lo | |
if err != nil { | ||
return err | ||
} | ||
log.Infof("#### Chain ID: %d", chainID) | ||
return nil | ||
}, | ||
}, | ||
{ | ||
name: "PendingNonceAt", | ||
f: func(ctx context.Context, p *provider) error { | ||
n, err := p.ec.PendingNonceAt(ctx, addr) | ||
if err != nil { | ||
return err | ||
} | ||
log.Infof("#### Pending nonce: %d", n) | ||
log.Debugf("#### Chain ID: %d", chainID) | ||
return nil | ||
}, | ||
}, | ||
|
@@ -1567,7 +1557,7 @@ func newCompatibilityTests(cb bind.ContractBackend, net dex.Network, log slog.Lo | |
if rpcTx.BlockNumber != nil { | ||
h = *rpcTx.BlockNumber | ||
} | ||
log.Infof("#### RPC Tx is nil? %t, block number: %q", rpcTx.tx == nil, h) | ||
log.Debugf("#### RPC Tx is nil? %t, block number: %q", rpcTx.tx == nil, h) | ||
return nil | ||
}, | ||
}, | ||
|
@@ -1587,7 +1577,7 @@ func domain(host string) string { | |
// requires by sending a series of requests and verifying the responses. If a | ||
// provider is found to be compliant, their domain name is added to a list and | ||
// stored in a file on disk so that future checks can be short-circuited. | ||
func checkProvidersCompliance(ctx context.Context, providers []*provider, net dex.Network, log slog.Logger) error { | ||
func checkProvidersCompliance(ctx context.Context, providers []*provider, net dex.Network, log dex.Logger) error { | ||
for _, p := range providers { | ||
// Need to run API tests on this endpoint. | ||
for _, t := range newCompatibilityTests(p.ec, net, log) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what this input parameter is about. Should it have been used or was this copy pasta from other methods like this?