Skip to content

Commit 4cf1b34

Browse files
Merge branch 'master' into nit-1280-switch-to-go-ethereum-pos-apis-to-write-new-blocks-and
2 parents 5e5c560 + 22399a7 commit 4cf1b34

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

accounts/abi/bind/bind.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@ func isKeyWord(arg string) bool {
7777
return true
7878
}
7979

80+
func duplicates(methods map[string]abi.Method) map[string]bool {
81+
var (
82+
identifiers = make(map[string]bool)
83+
dups = make(map[string]bool)
84+
)
85+
for _, method := range methods {
86+
identifiers, dups := identifiers, dups
87+
if identifiers[method.RawName] {
88+
dups[method.RawName] = true
89+
}
90+
identifiers[method.RawName] = true
91+
}
92+
return dups
93+
}
94+
8095
// Bind generates a Go wrapper around a contract ABI. This wrapper isn't meant
8196
// to be used as is in client code, but rather as an intermediate struct which
8297
// enforces compile time type safety and naming convention opposed to having to
@@ -121,6 +136,7 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
121136
callIdentifiers = make(map[string]bool)
122137
transactIdentifiers = make(map[string]bool)
123138
eventIdentifiers = make(map[string]bool)
139+
dups = duplicates(evmABI.Methods)
124140
)
125141

126142
for _, input := range evmABI.Constructor.Inputs {
@@ -132,12 +148,16 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
132148
for _, original := range evmABI.Methods {
133149
// Normalize the method for capital cases and non-anonymous inputs/outputs
134150
normalized := original
135-
normalizedName := methodNormalizer[lang](alias(aliases, original.Name))
136151
// Ensure there is no duplicated identifier
137152
var identifiers = callIdentifiers
138153
if !original.IsConstant() {
139154
identifiers = transactIdentifiers
140155
}
156+
name := original.RawName
157+
if dups[original.RawName] {
158+
name = fmt.Sprintf("%s%x", original.RawName, original.ID)
159+
}
160+
normalizedName := methodNormalizer[lang](alias(aliases, name))
141161
// Name shouldn't start with a digit. It will make the generated code invalid.
142162
if len(normalizedName) > 0 && unicode.IsDigit(rune(normalizedName[0])) {
143163
normalizedName = fmt.Sprintf("M%s", normalizedName)

accounts/abi/bind/bind_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,7 @@ var bindTests = []struct {
14861486
}
14871487
}
14881488
}()
1489-
contract.Foo(auth, big.NewInt(1), big.NewInt(2))
1489+
contract.Foo04bc52f8(auth, big.NewInt(1), big.NewInt(2))
14901490
sim.Commit()
14911491
select {
14921492
case n := <-resCh:
@@ -1497,7 +1497,7 @@ var bindTests = []struct {
14971497
t.Fatalf("Wait bar0 event timeout")
14981498
}
14991499
1500-
contract.Foo0(auth, big.NewInt(1))
1500+
contract.Foo2fbebd38(auth, big.NewInt(1))
15011501
sim.Commit()
15021502
select {
15031503
case n := <-resCh:

eth/tracers/api.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ func (api *API) blockByHash(ctx context.Context, hash common.Hash) (*types.Block
128128
if block == nil {
129129
return nil, fmt.Errorf("block %s not found", hash.Hex())
130130
}
131+
canonical := rawdb.ReadCanonicalHash(api.backend.ChainDb(), block.NumberU64())
132+
if hash != canonical {
133+
return nil, fmt.Errorf("hash %s is not currently canonical", hash.Hex())
134+
}
131135
return block, nil
132136
}
133137

internal/ethapi/api.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,13 +1178,14 @@ func doCall(ctx context.Context, b Backend, args TransactionArgs, state *state.S
11781178
func updateHeaderForPendingBlocks(blockNrOrHash rpc.BlockNumberOrHash, header *types.Header) *types.Header {
11791179
if blockNrOrHash.BlockNumber != nil &&
11801180
*blockNrOrHash.BlockNumber == rpc.PendingBlockNumber {
1181-
headerCopy := *header
1181+
headerCopy := types.CopyHeader(header)
11821182
now := uint64(time.Now().Unix())
11831183
if now > headerCopy.Time {
11841184
headerCopy.Time = now
11851185
}
11861186
headerCopy.Number = new(big.Int).Add(headerCopy.Number, common.Big1)
1187-
return &headerCopy
1187+
headerCopy.ParentHash = header.Hash()
1188+
return headerCopy
11881189
}
11891190
return header
11901191
}

0 commit comments

Comments
 (0)