Skip to content

Commit 697f46c

Browse files
committed
updates
1 parent 998fdc2 commit 697f46c

File tree

11 files changed

+89
-24
lines changed

11 files changed

+89
-24
lines changed

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ require (
66
github.com/coinbase/rosetta-sdk-go v0.8.3
77
github.com/coinbase/rosetta-sdk-go/types v1.0.0
88
github.com/gin-gonic/gin v1.10.0
9-
github.com/multiversx/mx-chain-core-go v1.4.0
10-
github.com/multiversx/mx-chain-go v1.10.1
9+
github.com/multiversx/mx-chain-core-go v1.4.2-0.20260219122727-014ae9f9311f
10+
github.com/multiversx/mx-chain-go v1.11.1
1111
github.com/multiversx/mx-chain-logger-go v1.1.0
12-
github.com/multiversx/mx-chain-proxy-go v1.3.0
12+
github.com/multiversx/mx-chain-proxy-go v1.4.0
1313
github.com/multiversx/mx-chain-storage-go v1.1.0
1414
github.com/stretchr/testify v1.10.0
1515
github.com/urfave/cli v1.22.16
@@ -44,7 +44,7 @@ require (
4444
github.com/mr-tron/base58 v1.2.0 // indirect
4545
github.com/multiversx/mx-chain-communication-go v1.3.0 // indirect
4646
github.com/multiversx/mx-chain-crypto-go v1.3.0 // indirect
47-
github.com/multiversx/mx-chain-es-indexer-go v1.9.1 // indirect
47+
github.com/multiversx/mx-chain-es-indexer-go v1.9.3-0.20260112102658-97d6a0ceb5f6 // indirect
4848
github.com/multiversx/mx-chain-vm-common-go v1.6.0 // indirect
4949
github.com/pelletier/go-toml v1.9.3 // indirect
5050
github.com/pelletier/go-toml/v2 v2.2.2 // indirect

go.sum

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
4747
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
4848
github.com/gabriel-vasile/mimetype v1.4.6 h1:3+PzJTKLkvgjeTbts6msPJt4DixhT4YtFNf1gtGe3zc=
4949
github.com/gabriel-vasile/mimetype v1.4.6/go.mod h1:JX1qVKqZd40hUPpAfiNTe0Sne7hdfKSbOqqmkq8GCXc=
50-
github.com/gin-contrib/cors v1.4.0 h1:oJ6gwtUl3lqV0WEIwM/LxPF1QZ5qe2lGWdY2+bz7y0g=
51-
github.com/gin-contrib/cors v1.4.0/go.mod h1:bs9pNM0x/UsmHPBWT2xZz9ROh8xYjYkiURUfmBoMlcs=
50+
github.com/gin-contrib/cors v1.6.0 h1:0Z7D/bVhE6ja07lI8CTjTonp6SB07o8bNuFyRbsBUQg=
51+
github.com/gin-contrib/cors v1.6.0/go.mod h1:cI+h6iOAyxKRtUtC6iF/Si1KSFvGm/gK+kshxlCi8ro=
5252
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
5353
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
5454
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
@@ -121,18 +121,18 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY
121121
github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o=
122122
github.com/multiversx/mx-chain-communication-go v1.3.0 h1:ziNM1dRuiR/7al2L/jGEA/a/hjurtJ/HEqgazHNt9P8=
123123
github.com/multiversx/mx-chain-communication-go v1.3.0/go.mod h1:gDVWn6zUW6aCN1YOm/FbbT5MUmhgn/L1Rmpl8EoH3Yg=
124-
github.com/multiversx/mx-chain-core-go v1.4.0 h1:p6FbfCzvMXF54kpS0B5mrjNWYpq4SEQqo0UvrMF7YVY=
125-
github.com/multiversx/mx-chain-core-go v1.4.0/go.mod h1:IO+vspNan+gT0WOHnJ95uvWygiziHZvfXpff6KnxV7g=
124+
github.com/multiversx/mx-chain-core-go v1.4.2-0.20260219122727-014ae9f9311f h1:kngckbX3TbZpU0LQpetUM8xNvUu/FtmZQtM66yoGcz0=
125+
github.com/multiversx/mx-chain-core-go v1.4.2-0.20260219122727-014ae9f9311f/go.mod h1:IO+vspNan+gT0WOHnJ95uvWygiziHZvfXpff6KnxV7g=
126126
github.com/multiversx/mx-chain-crypto-go v1.3.0 h1:0eK2bkDOMi8VbSPrB1/vGJSYT81IBtfL4zw+C4sWe/k=
127127
github.com/multiversx/mx-chain-crypto-go v1.3.0/go.mod h1:nPIkxxzyTP8IquWKds+22Q2OJ9W7LtusC7cAosz7ojM=
128-
github.com/multiversx/mx-chain-es-indexer-go v1.9.1 h1:Jg/4CLzIiwyrjuy+ZccEJ4TcvlHXnBUr5o3pclVitGo=
129-
github.com/multiversx/mx-chain-es-indexer-go v1.9.1/go.mod h1:t1rkD2vHXSI4EClig0h7+kRCSUCRrMF+emr4DHxFtfA=
130-
github.com/multiversx/mx-chain-go v1.10.1 h1:sRx7Ronn9SNB2oBMXJSl8kaJqm5iuluuGKNOec1h+XM=
131-
github.com/multiversx/mx-chain-go v1.10.1/go.mod h1:DavxpLJtHRLLLKU1xfrU1bAhgZD5paptiGS5KfX4Lco=
128+
github.com/multiversx/mx-chain-es-indexer-go v1.9.3-0.20260112102658-97d6a0ceb5f6 h1:ywYAthnCkytgSGfMBTBvojlBJh9o5zUmottZwaVYTd8=
129+
github.com/multiversx/mx-chain-es-indexer-go v1.9.3-0.20260112102658-97d6a0ceb5f6/go.mod h1:F/BpaYVPuHN7POJN6gwvJfZ22diYtvz2576a+PWiPvw=
130+
github.com/multiversx/mx-chain-go v1.11.1 h1:PC2cP10LEmfL18yMyfsMu0usTxa/ttXNQyi3BIVsuwM=
131+
github.com/multiversx/mx-chain-go v1.11.1/go.mod h1:7c9Qvi3lvE0wuHP/xTxbjs1GvTO/7W4NGmzT9IDsJCM=
132132
github.com/multiversx/mx-chain-logger-go v1.1.0 h1:97x84A6L4RfCa6YOx1HpAFxZp1cf/WI0Qh112whgZNM=
133133
github.com/multiversx/mx-chain-logger-go v1.1.0/go.mod h1:K9XgiohLwOsNACETMNL0LItJMREuEvTH6NsoXWXWg7g=
134-
github.com/multiversx/mx-chain-proxy-go v1.3.0 h1:sEfgO8qEKnUotCnX5EPTb+XC+VNiJcbzvZaY9sLrSXg=
135-
github.com/multiversx/mx-chain-proxy-go v1.3.0/go.mod h1:hdCT241dL+3d4t5+g/OUeAfZ8H/Y72SbY7SNF7vp0us=
134+
github.com/multiversx/mx-chain-proxy-go v1.4.0 h1:fwGWr3q2j3oMqYSfupVuAIPyuOgGSDP/aAA2Q8MU4T0=
135+
github.com/multiversx/mx-chain-proxy-go v1.4.0/go.mod h1:kizqVThJggPV0cD29qeOCFhLwnrbuYQ7saGg+GzEOog=
136136
github.com/multiversx/mx-chain-storage-go v1.1.0 h1:M1Y9DqMrJ62s7Zw31+cyuqsnPIvlG4jLBJl5WzeZLe8=
137137
github.com/multiversx/mx-chain-storage-go v1.1.0/go.mod h1:o6Jm7cjfPmcc6XpyihYWrd6sx3sgqwurrunw3ZrfyxI=
138138
github.com/multiversx/mx-chain-vm-common-go v1.6.0 h1:M2zmf/ptEINciWxYCPLIkwOMTvvzWjELYYB+0MMQ5Gw=

server/provider/accounts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (provider *networkProvider) GetAccount(address string) (*resources.AccountO
2828
return data, nil
2929
}
3030

31-
// GetAccountNativeBalance gets the native balance by address
31+
// GetAccountBalance gets the native balance by address
3232
func (provider *networkProvider) GetAccountBalance(address string, tokenIdentifier string, options resources.AccountQueryOptions) (*resources.AccountBalanceOnBlock, error) {
3333
isNativeBalance := tokenIdentifier == provider.nativeCurrency.Symbol
3434
if isNativeBalance {

server/provider/networkProvider.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ func (provider *networkProvider) getBlockSummaryByNonce(nonce uint64) (resources
195195
Nonce: blockResponse.Data.Block.Nonce,
196196
Hash: blockResponse.Data.Block.Hash,
197197
PreviousBlockHash: blockResponse.Data.Block.PrevBlockHash,
198-
Timestamp: int64(blockResponse.Data.Block.Timestamp),
198+
Timestamp: blockResponse.Data.Block.Timestamp,
199+
TimestampMs: blockResponse.Data.Block.TimestampMs,
199200
}, nil
200201
}
201202

@@ -285,6 +286,7 @@ func createBlockCopy(block *api.Block) *api.Block {
285286
StateRootHash: block.StateRootHash,
286287
Status: block.Status,
287288
Timestamp: block.Timestamp,
289+
TimestampMs: block.TimestampMs,
288290
MiniBlocks: miniblocksCopy,
289291
}
290292
}

server/provider/nodeStatus.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (provider *networkProvider) GetNodeStatus() (*resources.AggregatedNodeStatu
1818
return nil, err
1919
}
2020

21-
latestNonce, err := getLatestNonceGivenHighestFinalNonce(plainNodeStatus.HighestFinalNonce)
21+
latestNonce, err := getLatestNonceGivenHighestFinalNonceAndLastExecutedNonce(plainNodeStatus.HighestFinalNonce, plainNodeStatus.LastExecutedNonce)
2222
if err != nil {
2323
return nil, err
2424
}
@@ -71,18 +71,23 @@ func (provider *networkProvider) getLatestBlockNonce() (uint64, error) {
7171
}
7272

7373
// In the context of scheduled transactions, make sure the N+1 block is final, as well.
74-
return getLatestNonceGivenHighestFinalNonce(nodeStatus.HighestFinalNonce)
74+
return getLatestNonceGivenHighestFinalNonceAndLastExecutedNonce(nodeStatus.HighestFinalNonce, nodeStatus.LastExecutedNonce)
7575
}
7676

77-
func getLatestNonceGivenHighestFinalNonce(highestFinalNonce uint64) (uint64, error) {
77+
func getLatestNonceGivenHighestFinalNonceAndLastExecutedNonce(highestFinalNonce uint64, lastExecutedNonce uint64) (uint64, error) {
7878
// Account for rollback-related edge cases while node is syncing (in conjunction with scheduled miniblocks).
7979
const nonceDelta = 2
8080

8181
if highestFinalNonce <= nonceDelta {
8282
return 0, errCannotGetLatestBlockNonce
8383
}
8484

85-
return highestFinalNonce - nonceDelta, nil
85+
nonceToReturn := highestFinalNonce - nonceDelta
86+
if lastExecutedNonce > 0 && nonceToReturn > lastExecutedNonce {
87+
return lastExecutedNonce, nil
88+
}
89+
90+
return nonceToReturn, nil
8691
}
8792

8893
func (provider *networkProvider) getOldestNonceWithHistoricalStateGivenNodeStatus(status *resources.NodeStatus) (uint64, error) {

server/provider/nodeStatus_test.go

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func TestNetworkProvider_GetNodeStatusWithSuccess(t *testing.T) {
6666
Hash: "00000998",
6767
PrevBlockHash: "00000997",
6868
Timestamp: 998,
69+
TimestampMs: 998200,
6970
},
7071
},
7172
}, nil
@@ -80,6 +81,7 @@ func TestNetworkProvider_GetNodeStatusWithSuccess(t *testing.T) {
8081
Hash: "00000300",
8182
PrevBlockHash: "00000299",
8283
Timestamp: 300,
84+
TimestampMs: 3002000,
8385
},
8486
},
8587
}, nil
@@ -102,13 +104,15 @@ func TestNetworkProvider_GetNodeStatusWithSuccess(t *testing.T) {
102104
Hash: "00000998",
103105
PreviousBlockHash: "00000997",
104106
Timestamp: 998,
107+
TimestampMs: 998200,
105108
}
106109

107110
expectedSummaryOfOldest := resources.BlockSummary{
108111
Nonce: 300,
109112
Hash: "00000300",
110113
PreviousBlockHash: "00000299",
111114
Timestamp: 300,
115+
TimestampMs: 3002000,
112116
}
113117

114118
nodeStatus, err := provider.GetNodeStatus()
@@ -164,8 +168,8 @@ func TestNetworkProvider_GetLatestBlockNonce(t *testing.T) {
164168
args.FirstHistoricalEpoch = 2
165169
args.NumHistoricalEpochs = 8
166170

167-
provider, err := NewNetworkProvider(args)
168-
require.Nil(t, err)
171+
provider, errC := NewNetworkProvider(args)
172+
require.Nil(t, errC)
169173
require.NotNil(t, provider)
170174

171175
t.Run("when HighestFinalNonce <= 2 (node didn't start syncing)", func(t *testing.T) {
@@ -207,6 +211,51 @@ func TestNetworkProvider_GetLatestBlockNonce(t *testing.T) {
207211
return 0, errors.New("unexpected request")
208212
}
209213

214+
nonce, err := provider.getLatestBlockNonce()
215+
require.Nil(t, err)
216+
require.Equal(t, uint64(40), nonce)
217+
})
218+
t.Run("when HighestFinalNonce is greater than LastExecutedNonce", func(t *testing.T) {
219+
t.Parallel()
220+
221+
observerFacade.CallGetRestEndPointCalled = func(baseUrl, path string, value interface{}) (int, error) {
222+
if path == "/node/status" {
223+
value.(*resources.NodeStatusApiResponse).Data = resources.NodeStatusApiResponsePayload{
224+
Status: resources.NodeStatus{
225+
HighestFinalNonce: 42,
226+
LastExecutedNonce: 39,
227+
},
228+
}
229+
230+
return 0, nil
231+
}
232+
233+
return 0, errors.New("unexpected request")
234+
}
235+
236+
nonce, err := provider.getLatestBlockNonce()
237+
require.Nil(t, err)
238+
require.Equal(t, uint64(39), nonce)
239+
})
240+
241+
t.Run("when HighestFinalNonce is greater than LastExecutedNonce, but LastExecutedNonce is zero", func(t *testing.T) {
242+
t.Parallel()
243+
244+
observerFacade.CallGetRestEndPointCalled = func(baseUrl, path string, value interface{}) (int, error) {
245+
if path == "/node/status" {
246+
value.(*resources.NodeStatusApiResponse).Data = resources.NodeStatusApiResponsePayload{
247+
Status: resources.NodeStatus{
248+
HighestFinalNonce: 42,
249+
LastExecutedNonce: 0,
250+
},
251+
}
252+
253+
return 0, nil
254+
}
255+
256+
return 0, errors.New("unexpected request")
257+
}
258+
210259
nonce, err := provider.getLatestBlockNonce()
211260
require.Nil(t, err)
212261
require.Equal(t, uint64(40), nonce)

server/resources/network.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type NodeStatus struct {
3434
CurrentEpoch uint32 `json:"erd_epoch_number"`
3535
HighestNonce uint64 `json:"erd_nonce"`
3636
HighestFinalNonce uint64 `json:"erd_highest_final_nonce"`
37+
LastExecutedNonce uint64 `json:"erd_last_executed_nonce"`
3738
}
3839

3940
// EpochStartApiResponse is an API resource

server/resources/resources.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type BlockSummary struct {
1818
Hash string
1919
PreviousBlockHash string
2020
Timestamp int64
21+
TimestampMs int64
2122
}
2223

2324
// Currency is an internal resource

server/services/blockService.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func (service *blockService) convertToRosettaBlock(block *api.Block) (*types.Blo
220220
Block: &types.Block{
221221
BlockIdentifier: blockToIdentifier(block),
222222
ParentBlockIdentifier: parentBlockIdentifier,
223-
Timestamp: timestampInMilliseconds(int64(block.Timestamp)),
223+
Timestamp: getTimestamp(block.Timestamp, block.TimestampMs),
224224
Transactions: transactions,
225225
Metadata: objectsMap{
226226
"shard": block.Shard,

server/services/converters.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ func timestampInMilliseconds(timestamp int64) int64 {
7272
return timestamp * 1000
7373
}
7474

75+
func getTimestamp(timestamp int64, timestampMS int64) int64 {
76+
if timestampMS > 0 {
77+
return timestampMS
78+
}
79+
return timestampInMilliseconds(timestamp)
80+
}
81+
7582
func stringToHex(value string) string {
7683
encoded := hex.EncodeToString([]byte(value))
7784
encoded = ensureEvenLengthOfHexString(encoded)

0 commit comments

Comments
 (0)