From 4a007aaa00ee6efa420f759cf21d795e6d9e20d7 Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Wed, 4 Sep 2024 09:49:21 +0800 Subject: [PATCH 1/3] feat: update lib --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 138995d..042641e 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module das-account-indexer go 1.18 require ( - github.com/dotbitHQ/das-lib v1.2.1-0.20240822060625-4e7afa931e67 + github.com/dotbitHQ/das-lib v1.2.1-0.20240823031424-6de110677a97 github.com/fsnotify/fsnotify v1.5.4 github.com/gin-gonic/gin v1.9.1 github.com/go-redis/redis v6.15.9+incompatible diff --git a/go.sum b/go.sum index 7805fd5..569f599 100644 --- a/go.sum +++ b/go.sum @@ -140,8 +140,8 @@ github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5O github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/dop251/goja v0.0.0-20211011172007-d99e4b8cbf48/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk= github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y= -github.com/dotbitHQ/das-lib v1.2.1-0.20240822060625-4e7afa931e67 h1:DVBGzVMAcZy/a2ytwcaFYhkA/DMka7RBbkv9Pmtz1Ag= -github.com/dotbitHQ/das-lib v1.2.1-0.20240822060625-4e7afa931e67/go.mod h1:WgHO3ZBtA0JY3l5N2gqssPxwvzoRYf4JKpQT6zyLH4s= +github.com/dotbitHQ/das-lib v1.2.1-0.20240823031424-6de110677a97 h1:NXCjR3TZ+hu+ISMc+RgNkL5UhLgJVQUcn0R2AfU8+8E= +github.com/dotbitHQ/das-lib v1.2.1-0.20240823031424-6de110677a97/go.mod h1:WgHO3ZBtA0JY3l5N2gqssPxwvzoRYf4JKpQT6zyLH4s= github.com/eclipse/paho.mqtt.golang v1.2.0/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts= github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/elazarl/goproxy v0.0.0-20221015165544-a0805db90819 h1:RIB4cRk+lBqKK3Oy0r2gRX4ui7tuhiZq2SuTtTCi0/0= From 54210ffcf9fa2eb9c0cb3d6c6f3d5fa6c642c280 Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Wed, 4 Sep 2024 14:52:20 +0800 Subject: [PATCH 2/3] feat: update lib --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 042641e..fae2f31 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module das-account-indexer go 1.18 require ( - github.com/dotbitHQ/das-lib v1.2.1-0.20240823031424-6de110677a97 + github.com/dotbitHQ/das-lib v1.2.1-0.20240904064959-9907eef8e150 github.com/fsnotify/fsnotify v1.5.4 github.com/gin-gonic/gin v1.9.1 github.com/go-redis/redis v6.15.9+incompatible diff --git a/go.sum b/go.sum index 569f599..4ccf715 100644 --- a/go.sum +++ b/go.sum @@ -140,8 +140,8 @@ github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5O github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/dop251/goja v0.0.0-20211011172007-d99e4b8cbf48/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk= github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y= -github.com/dotbitHQ/das-lib v1.2.1-0.20240823031424-6de110677a97 h1:NXCjR3TZ+hu+ISMc+RgNkL5UhLgJVQUcn0R2AfU8+8E= -github.com/dotbitHQ/das-lib v1.2.1-0.20240823031424-6de110677a97/go.mod h1:WgHO3ZBtA0JY3l5N2gqssPxwvzoRYf4JKpQT6zyLH4s= +github.com/dotbitHQ/das-lib v1.2.1-0.20240904064959-9907eef8e150 h1:vhu4F2J39sBNsT9lGvoIT3Q4YWRAd7fGUH8TFN1f2DU= +github.com/dotbitHQ/das-lib v1.2.1-0.20240904064959-9907eef8e150/go.mod h1:WgHO3ZBtA0JY3l5N2gqssPxwvzoRYf4JKpQT6zyLH4s= github.com/eclipse/paho.mqtt.golang v1.2.0/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts= github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/elazarl/goproxy v0.0.0-20221015165544-a0805db90819 h1:RIB4cRk+lBqKK3Oy0r2gRX4ui7tuhiZq2SuTtTCi0/0= From 112692710185f932ede182bbcbfed74d1befcea9 Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Wed, 11 Sep 2024 14:35:12 +0800 Subject: [PATCH 3/3] feat: update cache --- cmd/main.go | 29 ++++++++++++++++++++++++++--- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index a557127..e78ef13 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -8,6 +8,7 @@ import ( "das-account-indexer/http_server" "das-account-indexer/http_server/handle" "das-account-indexer/prometheus" + "encoding/json" "fmt" "github.com/dotbitHQ/das-lib/common" "github.com/dotbitHQ/das-lib/core" @@ -101,6 +102,7 @@ func runServer(ctx *cli.Context) error { core.WithDasContractCodeHash(env.ContractCodeHash), core.WithDasNetType(config.Cfg.Server.Net), core.WithTHQCodeHash(env.THQCodeHash), + core.WithDasRedis(red), } dasCore := core.NewDasCore(ctxServer, &wgServer, ops...) dasCore.InitDasContract(env.MapContract) @@ -114,6 +116,10 @@ func runServer(ctx *cli.Context) error { dasCore.RunAsyncDasConfigCell(time.Minute * 2) // config cell outpoint dasCore.RunAsyncDasSoScript(time.Minute * 5) // so + dasCore.RunSetConfigCellByCache([]core.CacheConfigCellKey{ + core.CacheConfigCellKeyCharSet, + core.CacheConfigCellKeyReservedAccounts, + }) log.Info("das contract ok") // tx builder @@ -202,8 +208,25 @@ func initApiServer(txBuilderBase *txbuilder.DasTxBuilderBase, dasCore *core.DasC common.ConfigCellTypeArgsPreservedAccount19, common.ConfigCellTypeArgsUnavailable, ) + var mapReservedAccounts = make(map[string]struct{}) + var mapUnAvailableAccounts = make(map[string]struct{}) if err != nil { - return fmt.Errorf("ConfigCellDataBuilderByTypeArgsList err: %s", err.Error()) + var cacheBuilder core.CacheConfigCellReservedAccounts + strCache, errCache := dasCore.GetConfigCellByCache(core.CacheConfigCellKeyReservedAccounts) + if errCache != nil { + log.Error("GetConfigCellByCache err: %s", errCache.Error()) + return fmt.Errorf("ConfigCellDataBuilderByTypeArgsList1 err: %s", err.Error()) + } else if strCache == "" { + return fmt.Errorf("ConfigCellDataBuilderByTypeArgsList2 err: %s", err.Error()) + } else if errCache = json.Unmarshal([]byte(strCache), &cacheBuilder); errCache != nil { + log.Error("json.Unmarshal err: %s", errCache.Error()) + return fmt.Errorf("ConfigCellDataBuilderByTypeArgsList3 err: %s", err.Error()) + } + mapReservedAccounts = cacheBuilder.MapReservedAccounts + mapUnAvailableAccounts = cacheBuilder.MapUnAvailableAccounts + } else { + mapReservedAccounts = builderConfigCell.ConfigCellPreservedAccountMap + mapUnAvailableAccounts = builderConfigCell.ConfigCellUnavailableAccountMap } // http server hs := &http_server.HttpServer{ @@ -217,8 +240,8 @@ func initApiServer(txBuilderBase *txbuilder.DasTxBuilderBase, dasCore *core.DasC DbDao: dbDao, DasCore: dasCore, TxBuilderBase: txBuilderBase, - MapReservedAccounts: builderConfigCell.ConfigCellPreservedAccountMap, - MapUnAvailableAccounts: builderConfigCell.ConfigCellUnavailableAccountMap, + MapReservedAccounts: mapReservedAccounts, + MapUnAvailableAccounts: mapUnAvailableAccounts, }, } hs.Run() diff --git a/go.mod b/go.mod index fae2f31..c2803a1 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module das-account-indexer go 1.18 require ( - github.com/dotbitHQ/das-lib v1.2.1-0.20240904064959-9907eef8e150 + github.com/dotbitHQ/das-lib v1.2.1-0.20240911061249-7263de02ee43 github.com/fsnotify/fsnotify v1.5.4 github.com/gin-gonic/gin v1.9.1 github.com/go-redis/redis v6.15.9+incompatible diff --git a/go.sum b/go.sum index 4ccf715..ddbc775 100644 --- a/go.sum +++ b/go.sum @@ -140,8 +140,8 @@ github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5O github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/dop251/goja v0.0.0-20211011172007-d99e4b8cbf48/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk= github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y= -github.com/dotbitHQ/das-lib v1.2.1-0.20240904064959-9907eef8e150 h1:vhu4F2J39sBNsT9lGvoIT3Q4YWRAd7fGUH8TFN1f2DU= -github.com/dotbitHQ/das-lib v1.2.1-0.20240904064959-9907eef8e150/go.mod h1:WgHO3ZBtA0JY3l5N2gqssPxwvzoRYf4JKpQT6zyLH4s= +github.com/dotbitHQ/das-lib v1.2.1-0.20240911061249-7263de02ee43 h1:F+yj2dafGdIqxm1teb4NKGNgOC6GlK6mfQT6eKrE4xk= +github.com/dotbitHQ/das-lib v1.2.1-0.20240911061249-7263de02ee43/go.mod h1:WgHO3ZBtA0JY3l5N2gqssPxwvzoRYf4JKpQT6zyLH4s= github.com/eclipse/paho.mqtt.golang v1.2.0/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts= github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/elazarl/goproxy v0.0.0-20221015165544-a0805db90819 h1:RIB4cRk+lBqKK3Oy0r2gRX4ui7tuhiZq2SuTtTCi0/0=