Skip to content

Commit

Permalink
Merge branch 'main' into dedug_failing_test
Browse files Browse the repository at this point in the history
  • Loading branch information
cristure authored Sep 11, 2024
2 parents 1455c96 + 397a5d7 commit c698a50
Show file tree
Hide file tree
Showing 19 changed files with 1,581 additions and 22 deletions.
17 changes: 17 additions & 0 deletions blockchain/DisabledBlockDataCacher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package blockchain

// DisabledBlockDataCache is a no-op implementation of the BlockDataCache interface.
// It does nothing and always returns empty results.
type DisabledBlockDataCache struct{}

func (n *DisabledBlockDataCache) Get(_ []byte) (interface{}, bool) {
return nil, false
}

func (n *DisabledBlockDataCache) Put(_ []byte, _ interface{}, _ int) bool {
return false
}

func (n *DisabledBlockDataCache) IsInterfaceNil() bool {
return n == nil
}
2 changes: 1 addition & 1 deletion blockchain/endpointProviders/baseEndpointProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
rawStartOfEpochValidators = "internal/json/startofepoch/validators/by-epoch/%d"
esdt = "address/%s/esdt/%s"
nft = "address/%s/nft/%s/nonce/%d"
nodeGetGuardianData = "address/%s/guardian-data"
nodeGetGuardianData = "address/%s/guardian-data"
isDataTrieMigrated = "address/%s/is-data-trie-migrated"
)

Expand Down
12 changes: 12 additions & 0 deletions blockchain/endpointProviders/nodeEndpointProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const (
nodeRawBlockByHashEndpoint = "internal/raw/block/by-hash/%s"
nodeRawBlockByNonceEndpoint = "internal/raw/block/by-nonce/%d"
nodeRawMiniBlockByHashEndpoint = "internal/raw/miniblock/by-hash/%s/epoch/%d"
nodeBlockByNonceEndpoint = "block/by-nonce/%d"
nodeGetBlockByHashEndpoint = "block/by-hash/%s"
)

// nodeEndpointProvider is suitable to work with a MultiversX node (observer)
Expand Down Expand Up @@ -53,6 +55,16 @@ func (node *nodeEndpointProvider) GetRestAPIEntityType() core.RestAPIEntityType
return core.ObserverNode
}

// GetBlockByNonce returns the block with the given nonce
func (node *nodeEndpointProvider) GetBlockByNonce(_ uint32, nonce uint64) string {
return fmt.Sprintf(nodeBlockByNonceEndpoint, nonce)
}

// GetBlockByHash returns the block with the given hash
func (node *nodeEndpointProvider) GetBlockByHash(_ uint32, hash string) string {
return fmt.Sprintf(nodeGetBlockByHashEndpoint, hash)
}

// IsInterfaceNil returns true if there is no value under the interface
func (node *nodeEndpointProvider) IsInterfaceNil() bool {
return node == nil
Expand Down
2 changes: 2 additions & 0 deletions blockchain/endpointProviders/nodeEndpointProvider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func TestNodeEndpointProvider_Getters(t *testing.T) {
assert.Equal(t, "internal/raw/block/by-hash/hex", provider.GetRawBlockByHash(2, "hex"))
assert.Equal(t, "internal/raw/block/by-nonce/3", provider.GetRawBlockByNonce(2, 3))
assert.Equal(t, "internal/raw/miniblock/by-hash/hex/epoch/4", provider.GetRawMiniBlockByHash(2, "hex", 4))
assert.Equal(t, "block/by-nonce/5", provider.GetBlockByNonce(2, 5))
assert.Equal(t, "block/by-hash/hex", provider.GetBlockByHash(2, "hex"))
assert.Equal(t, core.ObserverNode, provider.GetRestAPIEntityType())
assert.True(t, provider.ShouldCheckShardIDForNodeStatus())
}
12 changes: 12 additions & 0 deletions blockchain/endpointProviders/proxyEndpointProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const (
proxyRawBlockByHash = "internal/%d/raw/block/by-hash/%s"
proxyRawBlockByNonce = "internal/%d/raw/block/by-nonce/%d"
proxyRawMiniBlockByHash = "internal/%d/raw/miniblock/by-hash/%s/epoch/%d"
proxyBlockByNonce = "block/%d/by-nonce/%d"
proxyBlockByHash = "block/%d/by-hash/%s"
)

// proxyEndpointProvider is suitable to work with a MultiversX Proxy
Expand Down Expand Up @@ -53,6 +55,16 @@ func (proxy *proxyEndpointProvider) GetRestAPIEntityType() core.RestAPIEntityTyp
return core.Proxy
}

// GetBlockByNonce returns the block with the given nonce within the given shard
func (proxy *proxyEndpointProvider) GetBlockByNonce(shardID uint32, nonce uint64) string {
return fmt.Sprintf(proxyBlockByNonce, shardID, nonce)
}

// GetBlockByHash returns the block with the given hash within the given shard
func (proxy *proxyEndpointProvider) GetBlockByHash(shardID uint32, hash string) string {
return fmt.Sprintf(proxyBlockByHash, shardID, hash)
}

// IsInterfaceNil returns true if there is no value under the interface
func (proxy *proxyEndpointProvider) IsInterfaceNil() bool {
return proxy == nil
Expand Down
2 changes: 2 additions & 0 deletions blockchain/endpointProviders/proxyEndpointProvider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func TestProxyEndpointProvider_Getters(t *testing.T) {
assert.Equal(t, "internal/2/raw/block/by-hash/hex", provider.GetRawBlockByHash(2, "hex"))
assert.Equal(t, "internal/2/raw/block/by-nonce/3", provider.GetRawBlockByNonce(2, 3))
assert.Equal(t, "internal/2/raw/miniblock/by-hash/hex/epoch/4", provider.GetRawMiniBlockByHash(2, "hex", 4))
assert.Equal(t, "block/2/by-nonce/5", provider.GetBlockByNonce(2, 5))
assert.Equal(t, "block/2/by-hash/hex", provider.GetBlockByHash(2, "hex"))
assert.Equal(t, sdkCore.Proxy, provider.GetRestAPIEntityType())
assert.False(t, provider.ShouldCheckShardIDForNodeStatus())
}
8 changes: 7 additions & 1 deletion blockchain/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ var ErrNilRequest = errors.New("nil request")
// ErrNilProxy signals that a nil proxy has been provided
var ErrNilProxy = errors.New("nil proxy")

/// ErrNotUint64Bytes signals that the provided bytes do not represent a valid uint64 number
// ErrNotUint64Bytes signals that the provided bytes do not represent a valid uint64 number
var ErrNotUint64Bytes = errors.New("provided bytes do not represent a valid uint64 number")

// ErrInvalidBlockRange signals that the provided block range is invalid
var ErrInvalidBlockRange = errors.New("invalid block range: too many blocks to process")

// ErrNoBlockRangeProvided signals that no block range was provided
var ErrNoBlockRangeProvided = errors.New("no block range specified")

func createHTTPStatusError(httpStatusCode int, err error) error {
if err == nil {
err = ErrHTTPStatusCodeIsNotOK
Expand Down
2 changes: 2 additions & 0 deletions blockchain/factory/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type EndpointProvider interface {
GetESDTTokenData(addressAsBech32 string, tokenIdentifier string) string
GetNFTTokenData(addressAsBech32 string, tokenIdentifier string, nonce uint64) string
IsDataTrieMigrated(addressAsBech32 string) string
GetBlockByNonce(shardID uint32, nonce uint64) string
GetBlockByHash(shardID uint32, hash string) string
IsInterfaceNil() bool
}

Expand Down
11 changes: 10 additions & 1 deletion blockchain/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package blockchain

import (
"context"

"github.com/multiversx/mx-chain-core-go/data/api"
"github.com/multiversx/mx-chain-core-go/data/transaction"
"github.com/multiversx/mx-sdk-go/core"
Expand All @@ -17,6 +16,7 @@ type Proxy interface {
SendTransactions(ctx context.Context, txs []*transaction.FrontendTransaction) ([]string, error)
GetGuardianData(ctx context.Context, address core.AddressHandler) (*api.GuardianData, error)
ExecuteVMQuery(ctx context.Context, vmRequest *data.VmValueRequest) (*data.VmValuesResponseData, error)
FilterLogs(ctx context.Context, filter *core.FilterQuery) ([]string, error)
IsInterfaceNil() bool
}

Expand Down Expand Up @@ -55,6 +55,8 @@ type EndpointProvider interface {
GetESDTTokenData(addressAsBech32 string, tokenIdentifier string) string
GetNFTTokenData(addressAsBech32 string, tokenIdentifier string, nonce uint64) string
IsDataTrieMigrated(addressAsBech32 string) string
GetBlockByNonce(shardID uint32, nonce uint64) string
GetBlockByHash(shardID uint32, hash string) string
IsInterfaceNil() bool
}

Expand All @@ -63,3 +65,10 @@ type FinalityProvider interface {
CheckShardFinalization(ctx context.Context, targetShardID uint32, maxNoncesDelta uint64) error
IsInterfaceNil() bool
}

// BlockDataCache defines the methods required for a basic cache.
type BlockDataCache interface {
Get(key []byte) (value interface{}, ok bool)
Put(key []byte, value interface{}, sizeInBytes int) (evicted bool)
IsInterfaceNil() bool
}
Loading

0 comments on commit c698a50

Please sign in to comment.