mirror of
				https://github.com/Xahau/xahaud.git
				synced 2025-11-04 02:35:48 +00:00 
			
		
		
		
	import_vl_keys logic fix (flap fix) (#588)
This commit is contained in:
		@@ -94,21 +94,6 @@ Change::preflight(PreflightContext const& ctx)
 | 
			
		||||
                                  "of sfImportVLKey, sfActiveValidator";
 | 
			
		||||
            return temMALFORMED;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // if we do specify import_vl_keys in config then we won't approve keys
 | 
			
		||||
        // that aren't on our list
 | 
			
		||||
        if (ctx.tx.isFieldPresent(sfImportVLKey) &&
 | 
			
		||||
            !ctx.app.config().IMPORT_VL_KEYS.empty())
 | 
			
		||||
        {
 | 
			
		||||
            auto const& inner = const_cast<ripple::STTx&>(ctx.tx)
 | 
			
		||||
                                    .getField(sfImportVLKey)
 | 
			
		||||
                                    .downcast<STObject>();
 | 
			
		||||
            auto const pk = inner.getFieldVL(sfPublicKey);
 | 
			
		||||
            std::string const strPk = strHex(makeSlice(pk));
 | 
			
		||||
            if (ctx.app.config().IMPORT_VL_KEYS.find(strPk) ==
 | 
			
		||||
                ctx.app.config().IMPORT_VL_KEYS.end())
 | 
			
		||||
                return telIMPORT_VL_KEY_NOT_RECOGNISED;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return tesSUCCESS;
 | 
			
		||||
@@ -168,9 +153,42 @@ Change::preclaim(PreclaimContext const& ctx)
 | 
			
		||||
            return tesSUCCESS;
 | 
			
		||||
        case ttAMENDMENT:
 | 
			
		||||
        case ttUNL_MODIFY:
 | 
			
		||||
        case ttUNL_REPORT:
 | 
			
		||||
        case ttEMIT_FAILURE:
 | 
			
		||||
            return tesSUCCESS;
 | 
			
		||||
        case ttUNL_REPORT: {
 | 
			
		||||
            if (!ctx.tx.isFieldPresent(sfImportVLKey) ||
 | 
			
		||||
                ctx.app.config().IMPORT_VL_KEYS.empty())
 | 
			
		||||
                return tesSUCCESS;
 | 
			
		||||
 | 
			
		||||
            // if we do specify import_vl_keys in config then we won't approve
 | 
			
		||||
            // keys that aren't on our list and/or aren't in the ledger object
 | 
			
		||||
            auto const& inner = const_cast<ripple::STTx&>(ctx.tx)
 | 
			
		||||
                                    .getField(sfImportVLKey)
 | 
			
		||||
                                    .downcast<STObject>();
 | 
			
		||||
            auto const pkBlob = inner.getFieldVL(sfPublicKey);
 | 
			
		||||
            std::string const strPk = strHex(makeSlice(pkBlob));
 | 
			
		||||
            if (ctx.app.config().IMPORT_VL_KEYS.find(strPk) !=
 | 
			
		||||
                ctx.app.config().IMPORT_VL_KEYS.end())
 | 
			
		||||
                return tesSUCCESS;
 | 
			
		||||
 | 
			
		||||
            auto const pkType = publicKeyType(makeSlice(pkBlob));
 | 
			
		||||
            if (!pkType)
 | 
			
		||||
                return tefINTERNAL;
 | 
			
		||||
 | 
			
		||||
            PublicKey const pk(makeSlice(pkBlob));
 | 
			
		||||
 | 
			
		||||
            // check on ledger
 | 
			
		||||
            if (auto const unlRep = ctx.view.read(keylet::UNLReport());
 | 
			
		||||
                unlRep && unlRep->isFieldPresent(sfImportVLKeys))
 | 
			
		||||
            {
 | 
			
		||||
                auto const& vlKeys = unlRep->getFieldArray(sfImportVLKeys);
 | 
			
		||||
                for (auto const& k : vlKeys)
 | 
			
		||||
                    if (PublicKey(k[sfPublicKey]) == pk)
 | 
			
		||||
                        return tesSUCCESS;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return telIMPORT_VL_KEY_NOT_RECOGNISED;
 | 
			
		||||
        }
 | 
			
		||||
        default:
 | 
			
		||||
            return temUNKNOWN;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -357,6 +357,32 @@ class UNLReport_test : public beast::unit_test::suite
 | 
			
		||||
            BEAST_EXPECT(isImportVL(env, ivlKeys[0]) == true);
 | 
			
		||||
            BEAST_EXPECT(isImportVL(env, ivlKeys[1]) == false);
 | 
			
		||||
            BEAST_EXPECT(isActiveValidator(env, vlKeys[0]) == true);
 | 
			
		||||
 | 
			
		||||
            // now test unrecognised keys that are already present in the ledger
 | 
			
		||||
            // object (flap fix)
 | 
			
		||||
            l = std::make_shared<Ledger>(
 | 
			
		||||
                *l, env.app().timeKeeper().closeTime());
 | 
			
		||||
 | 
			
		||||
            // insert a ttUNL_REPORT pseudo into the open ledger
 | 
			
		||||
            env.app().openLedger().modify(
 | 
			
		||||
                [&](OpenView& view, beast::Journal j) -> bool {
 | 
			
		||||
                    STTx tx = createUNLRTx(l->seq(), ivlKeys[1], vlKeys[0]);
 | 
			
		||||
                    uint256 txID = tx.getTransactionID();
 | 
			
		||||
                    auto s = std::make_shared<ripple::Serializer>();
 | 
			
		||||
                    tx.add(*s);
 | 
			
		||||
                    env.app().getHashRouter().setFlags(txID, SF_PRIVATE2);
 | 
			
		||||
                    view.rawTxInsert(txID, std::move(s), nullptr);
 | 
			
		||||
                    return true;
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
            BEAST_EXPECT(hasUNLReport(env) == true);
 | 
			
		||||
 | 
			
		||||
            // close the ledger
 | 
			
		||||
            env.close();
 | 
			
		||||
 | 
			
		||||
            BEAST_EXPECT(isImportVL(env, ivlKeys[0]) == true);
 | 
			
		||||
            BEAST_EXPECT(isImportVL(env, ivlKeys[1]) == false);
 | 
			
		||||
            BEAST_EXPECT(isActiveValidator(env, vlKeys[0]) == true);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -1324,4 +1350,4 @@ createUNLRTx(
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}  // namespace test
 | 
			
		||||
}  // namespace ripple
 | 
			
		||||
}  // namespace ripple
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user