diff --git a/relay/lcp.go b/relay/lcp.go index df10c40..a126a77 100644 --- a/relay/lcp.go +++ b/relay/lcp.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "io" "log" "os" "path/filepath" @@ -13,13 +14,14 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + mapset "github.com/deckarep/golang-set/v2" + "github.com/hyperledger-labs/yui-relayer/core" + oias "github.com/oasisprotocol/oasis-core/go/common/sgx/ias" + lcptypes "github.com/datachainlab/lcp-go/light-clients/lcp/types" "github.com/datachainlab/lcp-go/relay/elc" "github.com/datachainlab/lcp-go/relay/enclave" "github.com/datachainlab/lcp-go/sgx/ias" - mapset "github.com/deckarep/golang-set/v2" - "github.com/hyperledger-labs/yui-relayer/core" - oias "github.com/oasisprotocol/oasis-core/go/common/sgx/ias" ) const lastEnclaveKeyInfoFile = "last_eki" @@ -46,26 +48,35 @@ func (pr *Prover) loadLastEnclaveKey(ctx context.Context) (*enclave.EnclaveKeyIn } func (pr *Prover) saveLastEnclaveKey(ctx context.Context, eki *enclave.EnclaveKeyInfo) error { - path, err := pr.lastEnclaveKeyInfoFilePath() + src, err := os.CreateTemp(os.TempDir(), lastEnclaveKeyInfoFile) if err != nil { return err } - f, err := os.CreateTemp(os.TempDir(), lastEnclaveKeyInfoFile) + defer src.Close() + + bz, err := json.Marshal(eki) if err != nil { return err } - defer f.Close() - bz, err := json.Marshal(eki) + if err = os.WriteFile(src.Name(), bz, 0600); err != nil { + return err + } + + path, err := pr.lastEnclaveKeyInfoFilePath() if err != nil { return err } - if _, err := f.Write(bz); err != nil { + dst, err := os.Create(path) + if err != nil { return err } - if err := os.Rename(f.Name(), path); err != nil { + defer dst.Close() + + if _, err = io.Copy(dst, src); err != nil { return err } + return nil } diff --git a/simapp/go.mod b/simapp/go.mod index 2305e05..b739545 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -127,8 +127,8 @@ require ( github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/prometheus/client_golang v1.14.0 // indirect - github.com/prometheus/client_model v0.3.0 // indirect + github.com/prometheus/client_golang v1.15.1 // indirect + github.com/prometheus/client_model v0.4.0 // indirect github.com/prometheus/common v0.42.0 // indirect github.com/prometheus/procfs v0.9.0 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect diff --git a/simapp/go.sum b/simapp/go.sum index 760d703..0da811c 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -826,6 +826,7 @@ github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3O github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw= github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y= +github.com/prometheus/client_golang v1.15.1/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= @@ -834,6 +835,7 @@ github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6T github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4= github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w= +github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU= github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA=