diff --git a/CHANGELOG-Agoric.md b/CHANGELOG-Agoric.md index 6006e30f7b018..789854678e6fd 100644 --- a/CHANGELOG-Agoric.md +++ b/CHANGELOG-Agoric.md @@ -67,6 +67,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* (baseapp) [#338](https://github.com/agoric-labs/cosmos-sdk/pull/338) Make sure we don't execute blocks beyond the halt height. Restored from [#305](https://github.com/agoric-labs/cosmos-sdk/pull/305) but compatible with older `SIGINT`, `SIGTERM` logic * (baseapp) [#413](https://github.com/agoric-labs/cosmos-sdk/pull/413) Ignore events from simulated transactions ## `v0.46.16-alpha.agoric.2.1` - 2024-03-08 @@ -85,7 +86,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## `v0.46.16-alpha.agoric.1` - 2024-02-05 -* Agoric/agoric-sdk#8224 Merge [cosmos/cosmos-sdk v0.46.16](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.16) +* Agoric/agoric-sdk#8224 Merge [cosmos/cosmos-sdk v0.46.16](https://github.com/osmos/cosmos-sdk/releases/tag/v0.46.16) ### Bug Fixes @@ -99,7 +100,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes -* (baseapp) [#337](https://github.com/agoric-labs/cosmos-sdk/pull/337) revert #305 which causes test failures in agoric-sdk +* (baseapp) [#337](https://github.com/agoric-labs/cosmos-sdk/pull/337) revert [#305](https://github.com/agoric-labs/cosmos-sdk/pull/305) which causes test failures in agoric-sdk ## `v0.45.16-alpha.agoric.1` - 2023-09-22 diff --git a/baseapp/abci.go b/baseapp/abci.go index bdfa922035635..a42cdac7aad16 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -5,8 +5,10 @@ import ( "encoding/json" "errors" "fmt" + "os" "sort" "strings" + "syscall" "time" "github.com/gogo/protobuf/proto" @@ -325,6 +327,20 @@ func (app *BaseApp) checkHalt(height int64, time time.Time) { if halt { app.logger.Info("halt per configuration", "height", app.haltHeight, "time", app.haltTime) + + // [AGORIC] Make a best-effort attempt to kill our process. + p, err := os.FindProcess(os.Getpid()) + if err == nil { + // attempt cascading signals in case SIGINT fails (os dependent) + _ = p.Signal(syscall.SIGINT) + _ = p.Signal(syscall.SIGTERM) + // Errors in these signal calls are not meaningful to us. We tried our + // best, but we don't care (and can't tell) if or how the signal handler + // responds. + } + + // Prevent the state machine from advancing to the next block, no matter how + // the signals were handled. panic(errors.New("halt application")) } } diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index afec5be81f561..c2c39db04674a 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -3,7 +3,10 @@ package baseapp import ( "encoding/json" "fmt" + "os" + "os/signal" "strings" + "syscall" "testing" "time" @@ -247,10 +250,16 @@ func TestABCI_HaltChain(t *testing.T) { {"halt-time", 0, 10, 1, 11, true}, } + sigs := make(chan os.Signal, 5) for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { + if tc.expHalt { + signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) + } + defer func() { rec := recover() + signal.Stop(sigs) var err error if rec != nil { err = rec.(error) @@ -258,6 +267,12 @@ func TestABCI_HaltChain(t *testing.T) { if !tc.expHalt { require.NoError(t, err) } else { + // ensure that we received the correct signals + require.Equal(t, syscall.SIGINT, <-sigs) + require.Equal(t, syscall.SIGTERM, <-sigs) + require.Equal(t, len(sigs), 0) + + // Check our error message. require.Error(t, err) require.True(t, strings.HasPrefix(err.Error(), "halt application")) }