forked from TrueCloudLab/frostfs-node
[#1151] morph/client: Cache notary transaction heights
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
e0dce1043a
commit
e10b8f53d6
3 changed files with 27 additions and 4 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"time"
|
||||
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
||||
|
@ -83,6 +84,7 @@ func New(key *keys.PrivateKey, endpoint string, opts ...Option) (*Client, error)
|
|||
|
||||
if cfg.singleCli != nil {
|
||||
return &Client{
|
||||
cache: initClientCache(),
|
||||
singleClient: blankSingleClient(cfg.singleCli, wallet.NewAccountFromPrivateKey(key), cfg),
|
||||
}, nil
|
||||
}
|
||||
|
@ -90,6 +92,7 @@ func New(key *keys.PrivateKey, endpoint string, opts ...Option) (*Client, error)
|
|||
endpoints := append(cfg.extraEndpoints, endpoint)
|
||||
|
||||
return &Client{
|
||||
cache: initClientCache(),
|
||||
multiClient: &multiClient{
|
||||
cfg: *cfg,
|
||||
account: wallet.NewAccountFromPrivateKey(key),
|
||||
|
@ -99,6 +102,13 @@ func New(key *keys.PrivateKey, endpoint string, opts ...Option) (*Client, error)
|
|||
}, nil
|
||||
}
|
||||
|
||||
func initClientCache() cache {
|
||||
c, _ := lru.New(100) // returns error only if size is negative
|
||||
return cache{
|
||||
txHeights: c,
|
||||
}
|
||||
}
|
||||
|
||||
// WithContext returns a client constructor option that
|
||||
// specifies the neo-go client context.
|
||||
//
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue