Skip to content

Commit

Permalink
Merge pull request #50 from multiversx/integrating-v1.7.12
Browse files Browse the repository at this point in the history
Integrating v1.7.12
  • Loading branch information
iulianpascalau authored Jun 4, 2024
2 parents 240a39c + 8c43ba4 commit 9275fa1
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 28 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/deploy-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Publish Docker image

env:
IMAGE_NAME: chainsimulator
REGISTRY_HOSTNAME: multiversx

on:
release:
types: [published]

jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
attestations: write
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.20.7
id: go

- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Build and run chain simulator to fetch configs
run: |
cd cmd/chainsimulator
go build
./chainsimulator --fetch-configs-and-close
- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${REGISTRY_HOSTNAME}/${IMAGE_NAME}

- name: Build and push Docker image
id: push
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,22 @@ Example:

### `POST /simulator/set-state`

This endpoint allows you to set the entire state for a provided list of addresses.
This endpoint allows you to set the entire state for a provided list of addresses. Additionally, this endpoint
will generate one block per shard to apply the address state, unless specified otherwise.

##### Request
- **Method:** POST
- **Path:** `/simulator/set-state`


- **URL parameter** `noGenerate`

##### URL Parameter: `noGenerate`
- **Description:**
- **Type:** Boolean
- **Optional:** Yes
- **Default:** `false`
- **Behavior:** Setting the noGenerate=true is useful when multiple calls to this
endpoint are required and the calls should be executed as fast as possible. In this case,
to reflect the state changes, the user should manually call the generate-blocks endpoint
##### Request Body
The request body should be a JSON object representing an array of object with the next format.

Expand Down Expand Up @@ -235,7 +244,16 @@ This endpoint allows you to set the entire state (also will clean the old state
##### Request
- **Method:** POST
- **Path:** `/simulator/set-state`

- **URL parameter** `noGenerate`
-
##### URL Parameter: `noGenerate`
- **Description:**
- **Type:** Boolean
- **Optional:** Yes
- **Default:** `false`
- **Behavior:** Setting the noGenerate=true is useful when multiple calls to this endpoint are required and the calls
should be executed as fast as possible. In this case, to reflect the state changes,
the user should manually call the generate-blocks endpoint

##### Request Body
The request body should be a JSON object representing an array of object with the next format.
Expand Down
2 changes: 0 additions & 2 deletions cmd/chainsimulator/config/nodeOverrideDefault.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# System overrides, DO NOT EDIT THIS FILE
OverridableConfigTomlValues = [
{ File = "enableEpochs.toml", Path = "EnableEpochs.StakeLimitsEnableEpoch", Value = "1000000" }, # disable stake limits
# TODO remove the following overrides when integrating a newer version of the node (greater than v1.7.10)
{ File = "systemSmartContractsConfig.toml", Path = "DelegationManagerSystemSCConfig.MinStakeAmount", Value = "1000000000000000000" }, # 1 EGLD as on mainnet
]
9 changes: 7 additions & 2 deletions cmd/chainsimulator/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"github.com/urfave/cli"
)

const nodeOverrideDefaultFilename = "./config/nodeOverrideDefault.toml"
const nodeOverrideDefaultFilename = "nodeOverrideDefault.toml"
const nodeOverrideDefaultPath = "./config/" + nodeOverrideDefaultFilename

var (
configurationFile = cli.StringFlag{
Expand All @@ -20,7 +21,7 @@ var (
Name: "node-override-config",
Usage: "The node's override configuration file to load. Can define multiple files separated by comma. " +
"Example: ./config/override1.toml,./config/override2.toml and so on",
Value: nodeOverrideDefaultFilename,
Value: nodeOverrideDefaultPath,
}
logLevel = cli.StringFlag{
Name: "log-level",
Expand Down Expand Up @@ -127,6 +128,10 @@ var (
Name: "skip-configs-download",
Usage: "The flag is used to specify whether to skip downloading configs",
}
fetchConfigsAndClose = cli.BoolFlag{
Name: "fetch-configs-and-close",
Usage: "This flag is used to specify to fetch all configs and close the chain simulator after",
}
)

func applyFlags(ctx *cli.Context, cfg *config.Config) {
Expand Down
9 changes: 7 additions & 2 deletions cmd/chainsimulator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func main() {
autoGenerateBlocks,
blockTimeInMs,
skipConfigsDownload,
fetchConfigsAndClose,
}

app.Authors = []cli.Author{
Expand Down Expand Up @@ -123,10 +124,14 @@ func startChainSimulator(ctx *cli.Context) error {
skipDownload := ctx.GlobalBool(skipConfigsDownload.Name)
nodeConfigs := ctx.GlobalString(pathToNodeConfigs.Name)
proxyConfigs := ctx.GlobalString(pathToProxyConfigs.Name)
fetchConfigsAndCloseBool := ctx.GlobalBool(fetchConfigsAndClose.Name)
err = fetchConfigs(skipDownload, cfg, nodeConfigs, proxyConfigs)
if err != nil {
return fmt.Errorf("%w while fetching configs", err)
}
if fetchConfigsAndCloseBool {
return nil
}

bypassTxsSignature := ctx.GlobalBool(bypassTransactionsSignature.Name)
log.Warn("signature", "bypass", bypassTxsSignature)
Expand Down Expand Up @@ -360,12 +365,12 @@ func determineOverrideConfigFiles(ctx *cli.Context) []string {
overrideFiles := strings.Split(ctx.GlobalString(nodeOverrideConfigurationFile.Name), overrideConfigFilesSeparator)

for _, filename := range overrideFiles {
if filename == nodeOverrideDefaultFilename {
if strings.Contains(filename, nodeOverrideDefaultFilename) {
return overrideFiles
}
}

return append([]string{nodeOverrideDefaultFilename}, overrideFiles...)
return append([]string{nodeOverrideDefaultPath}, overrideFiles...)
}

func removeANSIColorsForLoggerIfNeeded(disableAnsi bool) error {
Expand Down
5 changes: 1 addition & 4 deletions examples/setState/code-metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ def main():

provider.do_post(SET_STATE_URL, test_state)

num_blocks_to_generate = 10
provider.do_post(f"{GENERATE_BLOCKS_URL}/{num_blocks_to_generate}", {})

# for this address the code metadata should be empty as the address is not a valid SC address
response = provider.do_get_generic(f'address/erd1qyqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqlqnj4d')
account_response = response.get("account")
Expand All @@ -50,7 +47,7 @@ def main():
account_response = response.get("account")
code_metadata = account_response.get('codeMetadata', '')
if code_metadata != 'BAA=':
assert code_metadata != 'BAA=', "code metadata is different from 'BAA='"
assert code_metadata == 'BAA=', "code metadata is different from 'BAA='"


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.20
require (
github.com/gin-gonic/gin v1.9.1
github.com/multiversx/mx-chain-core-go v1.2.20
github.com/multiversx/mx-chain-go v1.7.10
github.com/multiversx/mx-chain-go v1.7.12
github.com/multiversx/mx-chain-logger-go v1.0.14
github.com/multiversx/mx-chain-proxy-go v1.1.48
github.com/pelletier/go-toml v1.9.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-crypto-go v1.2.11 h1:MNPJoiTJA5/tedYrI0N22OorbsKD
github.com/multiversx/mx-chain-crypto-go v1.2.11/go.mod h1:pcZutPdfLiAFytzCU3LxU3s8cXkvpNqquyitFSfoF3o=
github.com/multiversx/mx-chain-es-indexer-go v1.4.21 h1:rzxXCkgOsqj67GRYtqzKuf9XgHwnZLTZhU90Ck3VbrE=
github.com/multiversx/mx-chain-es-indexer-go v1.4.21/go.mod h1:V9xxOBkfV7GjN4K5SODaOetoGVpQm4snibMVPCjL0Kk=
github.com/multiversx/mx-chain-go v1.7.10 h1:tQUFcKeaCN5gVVHK8sZ7Oyk9Mzi9lS/DwPKJ2z0UCs0=
github.com/multiversx/mx-chain-go v1.7.10/go.mod h1:HwklJGQfMpv/yyF4oLpxjwdKCawspv1JjdgezlWBpRQ=
github.com/multiversx/mx-chain-go v1.7.12 h1:cQ3g5sFZEcQmIRwi/wt+K/3d5nIwCMQRC1ZnJDRuRY4=
github.com/multiversx/mx-chain-go v1.7.12/go.mod h1:HwklJGQfMpv/yyF4oLpxjwdKCawspv1JjdgezlWBpRQ=
github.com/multiversx/mx-chain-logger-go v1.0.14 h1:PRMpAvXE7Nec2d//QNmbYfKVHMomOKmcN4UXurQWX9o=
github.com/multiversx/mx-chain-logger-go v1.0.14/go.mod h1:bDfHSdwqIimn7Gp8w+SH5KlDuGzJ//nlyEANAaTSc3o=
github.com/multiversx/mx-chain-proxy-go v1.1.48 h1:gmunv+2oimIN8ejlVAN7eWP7mt38So1WvsyiR3+94SU=
Expand Down
26 changes: 22 additions & 4 deletions pkg/facade/simulatorFacade.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,21 @@ func (sf *simulatorFacade) SetKeyValueForAddress(address string, keyValueMap map
}

// SetStateMultiple will set the entire state for the provided addresses
func (sf *simulatorFacade) SetStateMultiple(stateSlice []*dtos.AddressState) error {
return sf.simulator.SetStateMultiple(stateSlice)
func (sf *simulatorFacade) SetStateMultiple(stateSlice []*dtos.AddressState, noGenerate bool) error {
err := sf.simulator.SetStateMultiple(stateSlice)
if err != nil {
return err
}

if noGenerate {
return nil
}

return sf.simulator.GenerateBlocks(1)
}

// SetStateMultipleOverwrite will set the entire state for the provided address and cleanup the old state of the provided addresses
func (sf *simulatorFacade) SetStateMultipleOverwrite(stateSlice []*dtos.AddressState) error {
func (sf *simulatorFacade) SetStateMultipleOverwrite(stateSlice []*dtos.AddressState, noGenerate bool) error {
for _, state := range stateSlice {
// TODO MX-15414
err := sf.simulator.RemoveAccounts([]string{state.Address})
Expand All @@ -63,7 +72,16 @@ func (sf *simulatorFacade) SetStateMultipleOverwrite(stateSlice []*dtos.AddressS
}
}

return sf.simulator.SetStateMultiple(stateSlice)
err := sf.simulator.SetStateMultiple(stateSlice)
if err != nil {
return err
}

if noGenerate {
return nil
}

return sf.simulator.GenerateBlocks(1)
}

// AddValidatorKeys will add the validator keys in the multi key handler
Expand Down
2 changes: 1 addition & 1 deletion pkg/facade/simulatorFacade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestSimulatorFacade_SetStateMultiple(t *testing.T) {
})
require.NoError(t, err)

err = facade.SetStateMultiple(providedStateSlice)
err = facade.SetStateMultiple(providedStateSlice, true)
require.NoError(t, err)
require.True(t, wasCalled)
}
Expand Down
32 changes: 28 additions & 4 deletions pkg/proxy/api/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const (
addValidatorsKeys = "/simulator/add-keys"
forceUpdateValidatorStatistics = "/simulator/force-reset-validator-statistics"
observersInfo = "/simulator/observers"

queryParamNoGenerate = "noGenerate"
)

type endpointsProcessor struct {
Expand Down Expand Up @@ -139,15 +141,31 @@ func (ep *endpointsProcessor) setKeyValue(c *gin.Context) {
shared.RespondWith(c, http.StatusOK, gin.H{}, "", data.ReturnCodeSuccess)
}

func getQueryParamNoGenerate(c *gin.Context) (bool, error) {
withResultsStr := c.Request.URL.Query().Get(queryParamNoGenerate)
if withResultsStr == "" {
return false, nil
}

return strconv.ParseBool(withResultsStr)
}

func (ep *endpointsProcessor) setStateMultiple(c *gin.Context) {
var stateSlice []*dtos.AddressState
err := c.ShouldBindJSON(&stateSlice)

noGenerate, err := getQueryParamNoGenerate(c)
if err != nil {
shared.RespondWithBadRequest(c, fmt.Sprintf("invalid query parameter %s, error: %s", queryParamNoGenerate, err.Error()))
return
}

err = c.ShouldBindJSON(&stateSlice)
if err != nil {
shared.RespondWithBadRequest(c, fmt.Sprintf("invalid state structure, error: %s", err.Error()))
return
}

err = ep.facade.SetStateMultiple(stateSlice)
err = ep.facade.SetStateMultiple(stateSlice, noGenerate)
if err != nil {
shared.RespondWithBadRequest(c, fmt.Sprintf("cannot set state, error: %s", err.Error()))
return
Expand All @@ -157,14 +175,20 @@ func (ep *endpointsProcessor) setStateMultiple(c *gin.Context) {
}

func (ep *endpointsProcessor) setStateMultipleOverwrite(c *gin.Context) {
noGenerate, err := getQueryParamNoGenerate(c)
if err != nil {
shared.RespondWithBadRequest(c, fmt.Sprintf("invalid query parameter %s, error: %s", queryParamNoGenerate, err.Error()))
return
}

var stateSlice []*dtos.AddressState
err := c.ShouldBindJSON(&stateSlice)
err = c.ShouldBindJSON(&stateSlice)
if err != nil {
shared.RespondWithBadRequest(c, fmt.Sprintf("invalid state structure, error: %s", err.Error()))
return
}

err = ep.facade.SetStateMultipleOverwrite(stateSlice)
err = ep.facade.SetStateMultipleOverwrite(stateSlice, noGenerate)
if err != nil {
shared.RespondWithBadRequest(c, fmt.Sprintf("cannot overwrite state, error: %s", err.Error()))
return
Expand Down
4 changes: 2 additions & 2 deletions pkg/proxy/api/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ type SimulatorFacade interface {
GenerateBlocks(numOfBlocks int) error
GetInitialWalletKeys() *dtos.InitialWalletKeys
SetKeyValueForAddress(address string, keyValueMap map[string]string) error
SetStateMultiple(stateSlice []*dtos.AddressState) error
SetStateMultipleOverwrite(stateSlice []*dtos.AddressState) error
SetStateMultiple(stateSlice []*dtos.AddressState, noGenerate bool) error
SetStateMultipleOverwrite(stateSlice []*dtos.AddressState, noGenerate bool) error
AddValidatorKeys(validators *dtosc.ValidatorKeys) error
GenerateBlocksUntilEpochIsReached(targetEpoch int32) error
ForceUpdateValidatorStatistics() error
Expand Down

0 comments on commit 9275fa1

Please sign in to comment.