Skip to content
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

VRF zero confirmation delay #11947

Merged
merged 12 commits into from
Feb 15, 2024
Merged
30 changes: 30 additions & 0 deletions common/client/mock_rpc_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions common/client/multi_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,17 @@ func (c *multiNode[CHAIN_ID, SEQ, ADDR, BLOCK_HASH, TX, TX_HASH, EVENT, EVENT_OP
return n.RPC().CallContract(ctx, attempt, blockNumber)
}

func (c *multiNode[CHAIN_ID, SEQ, ADDR, BLOCK_HASH, TX, TX_HASH, EVENT, EVENT_OPS, TX_RECEIPT, FEE, HEAD, RPC_CLIENT]) PendingCallContract(
ctx context.Context,
attempt interface{},
) (rpcErr []byte, extractErr error) {
n, err := c.selectNode()
if err != nil {
return rpcErr, err
}
return n.RPC().PendingCallContract(ctx, attempt)
}

// ChainID makes a direct RPC call. In most cases it should be better to use the configured chain id instead by
// calling ConfiguredChainID.
func (c *multiNode[CHAIN_ID, SEQ, ADDR, BLOCK_HASH, TX, TX_HASH, EVENT, EVENT_OPS, TX_RECEIPT, FEE, HEAD, RPC_CLIENT]) ChainID(ctx context.Context) (id CHAIN_ID, err error) {
Expand Down
4 changes: 4 additions & 0 deletions common/client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ type clientAPI[
msg interface{},
blockNumber *big.Int,
) (rpcErr []byte, extractErr error)
PendingCallContract(
ctx context.Context,
msg interface{},
) (rpcErr []byte, extractErr error)
CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
CodeAt(ctx context.Context, account ADDR, blockNumber *big.Int) ([]byte, error)
}
Expand Down
4 changes: 4 additions & 0 deletions core/chains/evm/client/chain_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ func (c *chainClient) CallContract(ctx context.Context, msg ethereum.CallMsg, bl
return c.multiNode.CallContract(ctx, msg, blockNumber)
}

func (c *chainClient) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error) {
return c.multiNode.PendingCallContract(ctx, msg)
}

// TODO-1663: change this to actual ChainID() call once client.go is deprecated.
func (c *chainClient) ChainID() (*big.Int, error) {
//return c.multiNode.ChainID(ctx), nil
Expand Down
5 changes: 5 additions & 0 deletions core/chains/evm/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type Client interface {
HeaderByHash(ctx context.Context, h common.Hash) (*types.Header, error)

CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error)

IsL2() bool
}
Expand Down Expand Up @@ -260,6 +261,10 @@ func (client *client) CallContract(ctx context.Context, msg ethereum.CallMsg, bl
return client.pool.CallContract(ctx, msg, blockNumber)
}

func (client *client) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error) {
return client.pool.PendingCallContract(ctx, msg)
}

func (client *client) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) {
return client.pool.CodeAt(ctx, account, blockNumber)
}
Expand Down
4 changes: 4 additions & 0 deletions core/chains/evm/client/erroring_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func (e *erroringNode) CallContract(ctx context.Context, msg ethereum.CallMsg, b
return nil, errors.New(e.errMsg)
}

func (e *erroringNode) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error) {
return nil, errors.New(e.errMsg)
}

func (e *erroringNode) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) {
return nil, errors.New(e.errMsg)
}
Expand Down
30 changes: 30 additions & 0 deletions core/chains/evm/client/mocks/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions core/chains/evm/client/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ type Node interface {
EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error)
SuggestGasPrice(ctx context.Context) (*big.Int, error)
CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error)
CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
HeaderByNumber(context.Context, *big.Int) (*types.Header, error)
HeaderByHash(context.Context, common.Hash) (*types.Header, error)
Expand Down Expand Up @@ -830,6 +831,33 @@ func (n *node) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumb

}

func (n *node) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) (val []byte, err error) {
ctx, cancel, ws, http, err := n.makeLiveQueryCtxAndSafeGetClients(ctx)
if err != nil {
return nil, err
}
defer cancel()
lggr := n.newRqLggr().With("callMsg", msg)

lggr.Debug("RPC call: evmclient.Client#PendingCallContract")
start := time.Now()
if http != nil {
val, err = http.geth.PendingCallContract(ctx, msg)
err = n.wrapHTTP(err)
} else {
val, err = ws.geth.PendingCallContract(ctx, msg)
err = n.wrapWS(err)
}
duration := time.Since(start)

n.logResult(lggr, err, duration, n.getRPCDomain(), "PendingCallContract",
"val", val,
)

return

}

func (n *node) BlockByNumber(ctx context.Context, number *big.Int) (b *types.Block, err error) {
ctx, cancel, ws, http, err := n.makeLiveQueryCtxAndSafeGetClients(ctx)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions core/chains/evm/client/null_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ func (nc *NullClient) CallContract(ctx context.Context, msg ethereum.CallMsg, bl
return nil, nil
}

func (nc *NullClient) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error) {
nc.lggr.Debug("PendingCallContract")
return nil, nil
}

func (nc *NullClient) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) {
nc.lggr.Debug("CodeAt")
return nil, nil
Expand Down
4 changes: 4 additions & 0 deletions core/chains/evm/client/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,10 @@ func (p *Pool) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumb
return p.selectNode().CallContract(ctx, msg, blockNumber)
}

func (p *Pool) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error) {
return p.selectNode().PendingCallContract(ctx, msg)
}

func (p *Pool) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) {
return p.selectNode().CodeAt(ctx, account, blockNumber)
}
Expand Down
28 changes: 28 additions & 0 deletions core/chains/evm/client/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,34 @@ func (r *rpcClient) CallContract(ctx context.Context, msg interface{}, blockNumb

}

func (r *rpcClient) PendingCallContract(ctx context.Context, msg interface{}) (val []byte, err error) {
ctx, cancel, ws, http, err := r.makeLiveQueryCtxAndSafeGetClients(ctx)
if err != nil {
return nil, err
}
defer cancel()
lggr := r.newRqLggr().With("callMsg", msg)
message := msg.(ethereum.CallMsg)

lggr.Debug("RPC call: evmclient.Client#PendingCallContract")
start := time.Now()
if http != nil {
val, err = http.geth.PendingCallContract(ctx, message)
err = r.wrapHTTP(err)
} else {
val, err = ws.geth.PendingCallContract(ctx, message)
err = r.wrapWS(err)
}
duration := time.Since(start)

r.logResult(lggr, err, duration, r.getRPCDomain(), "PendingCallContract",
"val", val,
)

return

}

func (r *rpcClient) LatestBlockHeight(ctx context.Context) (*big.Int, error) {
var height big.Int
h, err := r.BlockNumber(ctx)
Expand Down
Loading
Loading